- Home /
GetInstanceId range of possible values
Hi,
I'm creating a script to export out scene data and I have a couple of questions regarding object ids.
What is the maximum/minimum possible values for object ids accessed via Object#GetInstanceId?
I've seen that the id value can be positive or negative - is there a practical difference?
Also the values sometimes don't seem to be sequential (i.e. three cubes created at the same time have ids of -558, -11726 and -12668) - I was wondering why this was.
Cheers,
Answer by zeropoint · Apr 19, 2011 at 06:21 AM
1 - What is the maximum/minimum possible values for object ids accessed via Object#GetInstanceId?
Since Object.GetInstanceId
returns in int
which is System.Int32
in .NET perspective (CTS to be more specific), it's range is -2,147,483,648 to 2,147,483,647 or in other words -2^31 to (2^31 - 1).
2 - I've seen that the id value can be positive or negative - is there a practical difference?
Considering above fact, it probably makes no difference; also consider the following.
3 - Also the values sometimes don't seem to be sequential (i.e. three cubes created at the same time have ids of -558, -11726 and -12668) - I was wondering why this was.
The id
kind of things are generally generated using hash values algorithms; so you can't guarantee what the next number might be!
Hope this is helpful enough :)
If you really need these constants you can refer to int.$$anonymous$$inValue and int.$$anonymous$$axValue.
Wouldn't that cause problems when the hashing algorithm returns a value that is already used? If Unity checks the ID after generating the value, it seems to me that it computes more than necessary, starting with the $$anonymous$$imum int(perhaps unsigned for aesthetical reasons) value and counting up sounds less computational invasive. Aside from that, why computing the hashing algorithm at all if counting up is way more efficient?
Your answer

Follow this Question
Related Questions
InstanceIDtoObject namespace? 1 Answer
How push the object? 2 Answers
Attaching a Camera to the Player 3 Answers
Slicing Objects 1 Answer
How to activate a object with GUI button? (java script) 2 Answers