Instance ID problem

SOLVED

Dear Community,

I’ve got a GameObject with 2 empty child GameObjects. Im using the child GameObjects as triggers. I need to get the parent GOs InstanceID. Problem is, the same objects InstanceID is different depending on from where I read it out. So reading out the InstanceID from a script on the parent object gives me a different InstanceID the the one I get by reading it out from a script on the child object. Strangely, the returned InstanceIDs always differs by 2.

Example - Script on the parent object

returns e.g. -31200

Example - Script on the child object

returns e.g. -31202

Do you know why it behaves like this? Did I do any mistake?
The ugly workaround would to do a +2 to get to the same ID but I’d prefer a real solution.

Thanks for your help

Example - Script on the child Object needs

This is old, and you have solved it, but I see you never explained how you solved it.

In case anyone else is wondering, the problem is that

transform.parent

refers to the transform of the parent rather than the game object.

You need to use
transform.parent.gameObject.GetInstanceID();
to get the instance id of the parent game object.

1 Like