Lots of references

Discussion and help for Easy Save 3
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Lots of references

Post by Joel »

Thanks for sending that over.

The BaseClass works because it inherits from MonoBehaviour, so Easy Save knows that all items will be UnityEngine.Object types. The interface provides no such information to the serializer so it serializes the items by the default of ES3.ReferenceMode.ByRefAndValue.

It should also be noted that saving by reference and value shouldn't necessarily cause any issues apart from making the file slightly larger because loading by reference ensures that the data is always loaded into the same reference, and if the data is part of the same serialization tree then the fields will be the same.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
aloxuhik
Posts: 8
Joined: Wed Jul 12, 2023 6:54 am

Re: Lots of references

Post by aloxuhik »

It's not just slightly bigger if you have 100 objects all saved 10 times...

And it is causing problem as I mentioned before...

Can I somehow tell serializer that interface will be Unity Object?
Now I retype it to base class in Reader/Writer in ES3Type Script. But I need to do it for each Type in future, not just once for mentioned interface.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Lots of references

Post by Joel »

Generally in this situation you should be using the base class rather than the interface, as an interface only indicates what methods a class will have, not anything about the structure of that class.

The only way I can think of being able to do this is to manually create an ES3Type for UserInterface which inherits from ES3ComponentType and writes no fields. However, be aware that if any of your UserInterface's don't derive from Component then this will break:

Code: Select all

namespace ES3Types
{
    [UnityEngine.Scripting.Preserve]
    public class ES3UserType_TestInterface : ES3ComponentType
    {
        public ES3UserType_TestInterface() : base(typeof(TestInterface)){}

        protected override void WriteComponent(object obj, ES3Writer writer){}
        protected override void ReadComponent<T>(ES3Reader reader, object obj){}
    }
}
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
aloxuhik
Posts: 8
Joined: Wed Jul 12, 2023 6:54 am

Re: Lots of references

Post by aloxuhik »

Worked like a charm!

Thank you for your support.

Cheers
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Lots of references

Post by Joel »

Glad to hear it, let me know if you run into any other issues :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply