Serialized field only compiled for editor

I was wondering if having a serialized field only compiled for Editor mode has any negative effects.

public class Foo : MonoBehaviour {

#if UnityEditor
public int Cerealized;
[SerializeField]
public int AlsoCerealized;
#endif

}

1 Like

Bump. Does this cause the serialization system to barf in some evil way when it’s deserializing at runtime?

I would think there aren’t any references to it in the build so it if there were any lingering data it would just be unused garbage. The compiler might be smart enough to throw it out. Not sure on the specifics. Are you seeing some weird issue?

Also, why not just use editor classes?

There are some scenarios where you want artists to drive a behavior while the game is playing, such as within a MonoBehaviour, that shouldn’t be available at runtime on device. Such as app theming, where an actual build wouldn’t have multiple themes, but in the editor it still does.