Does Unity recycle GetInstanceID in the same session?

For example, I spawn Gameobject A and it has InstanceID 123.

I then destroy Gameobject A, and spawn Gameobject B.

Is it possible for Gameobject B to have instanceID 123 now that Gameobject A no longer exists?

I would start with the docs. Anything not promised should not be relied upon.

The docs only mention that the InstanceIDs are guaranteed to be unique, nothing about if they are recycled when a GO is destroyed. Guess it’s safer to assume they will be recycled, huh :slight_smile:

1 Like

It’s implemented as an ever increasing unsigned integer, so they shouldn’t be recycled, unless you run your game long enough that it overflows and starts from 0 again (which is possible on 32-bit platforms, but unlikely on 64-bit platforms).

1 Like

That’s exactly what I was hoping for, thanks for confirming!