Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

get_gameObject is not allowed to be called during serialization

Discussion in '5.4 Beta' started by Hyp-X, Apr 19, 2016.

  1. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    438
    I get this error during build creation:
    get_gameObject is not allowed to be called during serialization, call it from Awake or Start instead.
    It's because of the following OnValidate() event handler:

    void OnValidate()
    {
    #if UNITY_EDITOR
    if (PrefabUtility.GetPrefabType(gameObject) != PrefabType.Prefab)​
    #endif
    {
    DoSomething();​
    }​
    }

    This is important editor functionality, but is not needed during building.
    Is there an easy way to detect that we are running in build mode?
     
  2. Deleted User

    Deleted User

    Guest

    What are the exact field/property declarations you have in that script?