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

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.

Maybe a question better asked on the dedicated Prefab forum?

I can move your post if you wish.

@MelvMay yes please :slight_smile:

1 Like