- Home /
Do objects have unique id?
In my game, I have a lot of cloned objects. All of them have the same name and I don't know how to distinguish them. Do objects in Unity have something like unique id?
How are you creating them? Can you not set their names to something unique yourself, when you do so?
Answer by Eric5h5 · May 05, 2013 at 07:44 PM
Can I ask, is this id permanent. I am thinking of using it as an identifier for a save/load system, but if it were to change it would break saves.
It's not permanent; the only guarantee is that it's unique.
Answer by RKSandswept · Jun 11, 2015 at 03:01 AM
I implementd some simple C++ for UIDs. Then the NPC class has a uid on the server that is unique and replicate4d.
The .h file
static int32 nextUid;
UFUNCTION(BlueprintCallable, Category = TDLHelpers)
static int32 GetNextTDLUID();
The .cpp
int32 UtdlBlueprintHelpers::nextUid = 1;
int32 UtdlBlueprintHelpers::GetNextTDLUID()
{
return nextUid++;
}
@Eric5h5 sure it does. You can implement C++ (or any native/static/linked/managed code) in Unity using their Plugins system. This method that @R$$anonymous$$Sanswept has provided would work just fine. However, it isn't really effective for this question.
Your answer
Follow this Question
Related Questions
How to get some unique identifier for GameObjects? 1 Answer
Is deviceUniqueIdentifier actually unique? 0 Answers
iPhone Unique Identifier 1 Answer
Making Duplicate Terrain Unique? 1 Answer