Game Object unique ID for search

Looking for a game object unique id in the scene.

I am working on an Editor Mode tool that should make a snapshot of certain objects in a scene so I can reset the state of those objects after they were modified in a distant future.

I thought it is a trivial case since each game object has the InstanceId. Unfortunately, I found out that those InstanceId’s are changing after I close and reopen the editor.

I cannot use GameObject.Find since I have object trees with the same objects names.

Do you have any suggestions or can point me in a right direction?

It is probably best to just add a specific identifier component to each GameObject, giving it a unique identifier.

I’ve seen other tools do this and it seems to work out pretty good. That way you’re playing in a “safe” way. Be sure to use Undo.RecordObject() so that the change of adding a component gets saved.

By a “specific identifier” do you mean to attach a script?

Yeah, that’s how a tool I used called LazyLayout did it: every item it controlled had an identifier.