Sign in to follow this  

Why do entities need unique IDs?

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my last project, I put unique id in my entity class, but I ended up never using it.

 

Why do we need it?

Share this post


Link to post
Share on other sites

I use id's mostly for serializing/deserializing data.  it's also nice to have id's for looking up objects, for telling which object is a problem in a debug output. id's are very handy for a variety of reasons, if you can't see their use, then just try writing a system which can save and load your game at any given time.

Share this post


Link to post
Share on other sites

They're an alternative to using pointers.

and are also pretty useful if code interacts over a network (say, for client/server gaming), as they are typically much more "general" than pointers are, or sometimes for otherwise synchronizing between code which doesn't directly share data structures.

Share this post


Link to post
Share on other sites

Don't forget the ability to move objects around in memory (with pointers you can't do this, but if they're referenced by ID then you only need to update where the ID points rather than looking for the pointer about everywhere). Doing this can matter depending on how you allocate memory (especially if you're trying to avoid cache misses).

Share this post


Link to post
Share on other sites

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this