Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

PrefabStageUtility.GetPrefabStage(gameObject) not always accurate first frame?

Discussion in 'Prefabs' started by Maisey, Sep 8, 2022.

  1. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Hello,

    I'm having problem, possibly a Unity bug. Seems to be same behaviour in Unity 2020, 2021.

    I'm trying to find out when I'm inside the Prefab Editing Mode and most of the times it works by checking if PrefabStageUtility.GetPrefabStage(gameObject) != null. But on some objects I enter a state where PrefabStageUtility.GetPrefabStage(gameObject) == null the same frame I enter the Prefab Editing Mode (when OnValidate is called).

    It seems the only way for me to work around this is to check if gameObject.scene.isSubScene == true. Is this really the recommended approach? It seems very haxy...

    The problem when I'm in this state is that some variables that should have been serialized since before seems to be null (only this frame), which causes a lookup and other issues.
     
    Last edited: Sep 8, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Maybe a question better asked on the dedicated Prefab forum?

    I can move your post if you wish.
     
  3. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    MelvMay likes this.