- Home /
Does GetInstanceID ever change on an object?
Does GetInstanceID ever, EVER change for a unique gameobject?
Let's say I have a scene and a gameobject, Cube. It's just a prefab placed in the scene, not loaded dynamically or anything. Its ID is 12345. Will it be 12345 next time I run the game? Reload the scene, or go to a different scene and return? Run on a different system, load the scene async, etc etc etc.
I'm writing a save/load system to check if you've collected items and using the items' Instance IDs to see if they've been collected or not. I need to know what'll happen when the user reloads the game or loads their save data on a different system, or even a different platform.
Thanks!
Answer by siegeon · Dec 27, 2014 at 06:04 AM
After some testing here is what I have figured out. If I load the game the same way every time, and nothing changes then the id for the object is the same every time. But that only holds for the initial load. After that things tend to have different ids, especial if you have a user input instantiating things like bullets.
Answer by tomekkie2 · Dec 18, 2016 at 11:17 AM
Looks like: GetInstanceID - is just a session scope variable.
It doesn't change for the time of editor session.
It doesn't change for the time of game session.
I saved a scene in Editor. Then I have opened it once, closed wihout saving. Then I have opened it second time, closed wihout saving. Then I have opened it third time. Each time I was getting different InstanceID's on the same objects.