- Home /
Question by
Firestar9114 · Feb 27, 2019 at 07:31 PM ·
c#prefabeditor-scripting
Why is my prefab check failing?
So, I have added a callback to PrefabUtility.prefabInstanceUpdated
and in it I do a check,
public bool CheckIfIsPrefab()
{
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
IsPrefab = (prefabStage != null);
return IsPrefab;
}
However this seems to always be returning false... that seems wrong. Shouldn't this evaluate to true if a prefab was updated? This gets called on the get compontent of the gameObject that the callback passes in, for example:
[InitializeOnLoad]
public class Autorun
{
static Autorun()
{
EditorApplication.update += RunOnce;
}
static void RunOnce()
{
Item.SyncGUIDS();
PrefabUtility.prefabInstanceUpdated = new PrefabUtility.PrefabInstanceUpdated(PrefabInstanceUpdated);
EditorApplication.update -= RunOnce;
}
public static void PrefabInstanceUpdated(UnityEngine.GameObject gameObject)
{
Item item = gameObject.GetComponent<Item>();
if(item!=null)
{
item.CheckIfIsPrefab();
if (item.IsPrefab==false)
{
Debug.Log("instance callback: " + item);
}
else
{
Debug.Log("prefab callback: " + item);
}
}
}
}
Is this somehow related to this behavior with the new nested prefab system and prefab stages? https://answers.unity.com/questions/1604161/why-does-onvalidate-get-called-multiple-times-for.html
Comment