I came across the FGuid, so an unique identifier. Is it a alright to use these for inventory systems? The chance of generating the same ID for 2 items is extremely slim, but not 0 (Still it’s like winning the lottery).
I want to know other’s experiences with using these, and if you use them, do you check the existing IDs to prevent duplicates?
It’s almost impossible to have a GUID duplicated, it’s not like you’re making an MMORPG. Most inventories are just “I have this class and I have this quantity,” using a unique identifier is a waste of memory
Thank you for your answer. I’m trying to build a robust inventory system that should be able to handle hundreds of items with an equipment system. Usually I worked with struct arrays and Int IDs, but then I stumbled upon FGuids and found that an interesting approach.
Currently the system has a central array of all the items the player owns, some items are generated by the “server” but some by the player itself, so not one place that creates them all. Using FGuids I wanted to skip the whole need for references and pointers, and just use FGuids for referencing items in case of equipment etc. Would you say this is an appropriate use of FGuids or not?
If not, what are the usecases for FGuids? I’ve never seen anyone use them.
Also Husky’s reply says that it’s a waste of memory, but isn’t a FGuid just a string of numbers and letters making a unique code? And how does this compare to using pointers instead?
To add I’ve read on an article that Unique Identifiers like FGuid are an industry standard for inventory systems, but I’m realizing it probably was an AI article just making stuff up. Unfortunately there aren’t much sources on UE5 C++ that are trustworthy since AI was released, it’s all the same AI slop. I can’t even find the article anymore
this is exactly what they are for so don’t worry about it, and the memory footprint is tiny.
I’d only worry about size for network packages and even then this is fine, for general data this is nothing compared to say a texture.
i’d watch out for this though, there should always be a single source of truth, the player should just be asking the server to create it. even in a non networked model.
For tracking actors, When you have objects that spawn, get destroyed, move around the world, or get attached to players, it’s a good idea to use a GUID. That way, when loading data, you can quickly tell whether it belongs to the correct actor — especially in multiplayer environments.
On the other hand, in an inventory system where everything is saved to a database, I personally think a GUID is completely unnecessary — even for items with durability. Everything you need to recreate the object is already stored in the database, so adding an extra variable that doesn’t really add value just feels like a waste of memory. That being said, like others mentioned, a GUID is only a few bytes. Even with 500 items in an inventory, you wouldn’t even notice the difference.
The thing is, you shouldn’t store pointers at all. You should only save the bare minimum needed to recreate the object: the class type and the data structure used to initialize it.That said, if the equipment has an actual representation in the world — for example, a sword or armor that’s attached to the player — then yes, using a GUID is totally justifiable in that case.