- Online Community
Post Reply Forums » Game Design & Concepts » Object IDs

rss feed Print
Object IDs
Member #934
January 2001

I want to switch my object handler/registry to use an int-based key instead of string-based.

Edgar, I was trying to look to see how you get your IDs, but haven't found it yet. I'll keep looking.

Also, I've heard of UUID, anyone use that? Anyone have a good implementation?

I've seen some that just fake it as the randomness, of such a large number, makes it nearly unique.

Also, do I need 64 bit numbers or can I get away with less bits?

Edgar Reynaldo
Major Reynaldo
May 2007

I doubt there will ever be more than 4 billion objects live and dead, so an unsigned int works fine for me. I use 0xFFFFFFFF as an invalid id.

Also, the id serves as an index into the array of object info stored by the registry.

I have a fancy mutex guard around my logging calls and all eagle objects can be output to the log or an ostream.


Questions? Ask away. License is Mozilla Public License v2.

The actual code that generates the ID is here :

By itself it's not thread safe, but the ObjectRegistry uses it inside a mutex, so it is safe in the library.

Member #940
January 2001

DanielH said:

I've seen some that just fake it as the randomness, of such a large number, makes it nearly unique.

Yeah, version 4 UUIDs are basically 128 bit random numbers. Other versions include e.g. MAC address and timestamps to reduce the chance of clashes (perhaps to hedge against RNG flaws).

There is a standard: These are used a lot in the enterprise / database world. I think the main advantage of UUID formatting is that they are recognizable, and this helps when building web APIs. But IMHO for game engines there's no advantage of standard formatted UUIDs over just plain random numbers.

Member #5,749
April 2005

I needed a way of keeping track of which collectibles had been scooped up by the player in my TINS entry without having to go through and assign them all IDs myself.

In this case, a normal int, generated per-collectible at build time (which is 64-bit in Godot) was more than enough to not to have to worry about collisions. As the player collected stuff, I chucked the IDs into a hashset; whenever a level loads, collectibles whose IDs are in the hashset aren't spawned.

nb. this advice doesn't apply to use cases where security is important. More bits and more brains are preferable there. ;)

Website. It was
This isn't a game!

Member #16,660
April 2017

When the new 256K monitors come out you're going to need your windows to have 4 million objects. :'(

I also wonder if one day in terms of quantity, it can exceed 4 million. It is a good practice to always use uint32_t for IDs, I use it for all IDs, including the number of users on the server, which I'm fervently hoping that one day they will break it for the number of registered users. T_T

🌈🌈🌈 🌟 BlackRook WebSite 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023!

Post Reply
Go to: