Hello !
I would like to serialize a field only on some platforms and/or only on editor.
For example, let’s assume I have a MonoBehaviour, that should have a reference to some ScriptableObject only on Editor OR on Standalone (Win, Mac, OSX) builds :
public class SomeComponent : MonoBehaviour
{
#if UNITY_EDITOR || UNITY_STANDALONE
[SerializeField]
public SomeScriptableObjectType _someScriptableObject;
#endif
}
Will the above code compile correctly on every platform, in particular for the platforms where I don’t want to this ScriptableObject to be referenced and included in the build (e.g. Android, iOS…) ?
I remember that this kind of serialization depending on #define might cause errors like “different serialization layout”, but I cannot find precise info about it in the documentation.
It seems it is now supported, at least for serialization depending on editor or runtime :
https://docs.unity3d.com/2021.3/Documentation/Manual/script-Serialization.html#:~:text=: MonoBehaviour {-,#if UNITY_EDITOR,-public int m_intEditorOnly
If Unity cannot support conditional field serialization, for this use case, I will probably build and load an AssetBundle depending on the platform. But that seems a little overkill.