- Home /
IS there any DoNotPopulateAttribute for Non-UnityEngine.Object fields?
Hey buddies.
I kind of have to write a Iterator and Decorator for SerializedProperty. If anyone out there knows how to combine them in one class, like the SerializedProperty does, that would be great. Because when looking at the decompiled SerailizedProperty, It just shows external calls. My guess is, that Next(bool) just feeds SP new values. I kinda feel helplessly dumb... but that is not my actual Question. (Just if you happen to know the answer, tell me ;-) )
My actual Question is: how can I prevent Unity to populate nonUnityObject fields? IS there no attribute out there? I guess it would break Unity's Serialization System, but hey, I just had to ask, because having to check for _initializedXYZ all the time is freaking annoying^^
Answer by dCalle · Jun 13, 2018 at 10:57 AM
Alright so I just had to give me a refresher on Unity's Serialization:
Whenever you mark a class with [Serializable] every field linked to it (no matter the accessibility) will be autopopulated by Unity UNLESS you mark that field with [NonSerialized].
I don't know how that combines with ISerializationCallbackReceiver, but I guess it's worth figuring out how you can combine those too (with probably an extra cache placed somewhere) to prevent the ugly autopopulation loop/recursion I have to fight right now, while still saving its data (obviously, in that cache^^) If there's anyone out there currently working on that, please let me know ;-)