How can I determine whether a game object is a prefab asset or is an instance of a prefab within my scene?
I tried making a custom editor and doing
public override void OnInspectorGUI()
{
if (EditorUtility.IsPersistent(this.target))
{
Debug.Log("is persisent");
}
else
{
Debug.Log("is not persistent");
}
}
But whether I select the prefab asset in the Project view or I select the prefab instance in my scene, both scenarios print "is not persistent"
The reason I'm doing this is that I want to have a MonoBehaviour with a Guid
field, and the MonoBehaviour should generate a unique GUID for itself if it's part of a game object within a scene, but it should leave its Guid
field blank if its part of a prefab asset (so that each instance of the same prefab gets a unique GUID).