SaintsField icon indicating copy to clipboard operation
SaintsField copied to clipboard

[Feature Request] Serialize some fields via ISerializationCallbackReceiver like how is it done in OdinSerializer

Open potokaalex opened this issue 7 months ago • 6 comments

Hi, there seems to be a problem with displaying the enum name in the SaintsDictionary.

public SaintsDictionary<CollectableType, Color> Colors;
    public enum CollectableType
    {
        None = 0,
        Missile = 1,
        Coin = 2,
        Shield = 3,
    }

Image Ui toolkit Staints 4.13.0 Unity 2022.3.57f1

One more question: why not serialize the System.Collections.Generic.Dictionary via ISerializationCallbackReceiver how is it done in OdinSerializer?

potokaalex avatar May 20 '25 12:05 potokaalex

Thanks for this reporting!

This is fixed in dev branch. Will release it tomorrow :)

TylerTemp avatar May 20 '25 13:05 TylerTemp

Thanks for your labour! The issue of ISerializationCallbackReceiver is still relevant. I think this will get rid of your Data types, yes, it will require some kind of abstract class, similar to saintsMonoBehaviour and saintsScriptableObject, but it may even be a plus, in case of conflicts with other solutions, and will allow the user to choose.

potokaalex avatar May 20 '25 13:05 potokaalex

Hi,

ISerializationCallbackReceiver will not be considered for the following reasons:

  1. Unity itself still has some bugs in serialization. With years of Unity game developing, I sometime still face the issue that something is missing, broken, or Unity failed to refresh a target.
  2. Odin (Odin Serializer), based on my previous experience, has an issue with serialization Dictionary<T, enumFlagType>. I didn't find anyone mentioning it on the internet; it only happens in one simple script of mine, and I have never found a solution
  3. SaintsField is still heavily focused on portable types & attributes, which means most data types & attributes should work either fine or good enough (e.g., without SaintsEditor, all auto getters work just fine, but they will require you to click on that + button on a list/array)
  4. An IDE like Rider can not detect a custom MonoBehavior serializable dictionary

A ISerializationCallbackReceiver adds way too much complexity, and it will be a pain to locate a bug, even to see if it's related to this function.

TylerTemp avatar May 21 '25 03:05 TylerTemp

Hi,

this is fixed in 4.13.1, please have a try

Image

TylerTemp avatar May 21 '25 05:05 TylerTemp

Hi, thanks for the efficiency. I still don't like the idea of custom serializable standard types. Well, maybe I'll integrating odin serializer with saintsField in my project. If it succeeds, I will let you know.

potokaalex avatar May 21 '25 06:05 potokaalex

Im re-considering this feature because ISerializationCallbackReceiver should solve many problems, including #289

TylerTemp avatar Sep 08 '25 06:09 TylerTemp

Added in 5.5.3

TylerTemp avatar Dec 09 '25 09:12 TylerTemp