Question

in the mini challenge , i have used scene.isDirty which return bool if the scene has changed so that in a prefab situation the scene wouldn’t change and the unique Identifier will be empty. i tried it and it worked as intended.So is that a good approach?

 #if (UNITY_EDITOR)
// your code here
         void Update() {
 
            if(Application.IsPlaying(gameObject)) return;
           
            if(this.gameObject.scene.isDirty) 
            {
                
            SerializedObject serializedObject = new SerializedObject(this);
            SerializedProperty property = serializedObject.FindProperty("uniqueIdentifier");
 
            if(String.IsNullOrEmpty(property.stringValue))
            {
                property.stringValue = System.Guid.NewGuid().ToString();
                serializedObject.ApplyModifiedProperties();
            }
 
 
 
            }
            
        }
        
        
    #endif```

It’s fine. Sounds like a similar method that Unity itself uses to know if it needs to update things like the UI.

Yes, this should work fine. If the object you are editing is a prefab, then gameObject.scene.IsDirty should be false, and the rest of the code should never run. Using either IsDirty or testing the path will accomplish the same result.

Privacy & Terms