Confused about OnValidate bug

The lecture and previous discussion mention manually calling OnValidate() in Awake. However, the Awake method is in a #if UNITY_EDITOR block so it seems like it still wouldn’t get called in a production build. Should we make a new Awake method in an #else command block and call OnValidate() from there?

1 Like

If you have something accessing the editor code still in Awake(), I would still move it out of the larger #if UNITY_EDITOR block, and then enclose any Awake() code that relies on the Editor in it’s own #if block

void Awake()
{
     OnValidate();
#if UNITY_EDITOR
     // editor code
#endif
}

This topic was automatically closed after 68 minutes. New replies are no longer allowed.

Privacy & Terms