Unique Actor ID Variable at construction?

Hey there,

I have a question that’s been bothering me for quite some time. I have an actor that uses an ID which is a simple Integer value, nothing fancy. But in order to make a feature run properly, every placed actor has to have a different ID. For instance, for the first one ID=0, the second one ID=1 and so on. Until now I have to set them up manually for every actor in the map (ID is a public variable) which is a huge bummer.

Na what I need is: for every new actor placed, the actor itself should increase the ID variable by +1. So that the first actor placed has ID=0, second ID=1… how can I achieve that?

I have tested a Set ID + (Get ID +1) in the construction script, but that does only affect the ID, once the actor has been moved (and then increases the value depending on the units moved).

Thanks in advance,


Are you trying to create a new variable every time you spawn the actor? Or am I just misunderstanding the question?

Every time a new actor is spawned, the value for a special variable will be increased by +1.

Make id 0 invalid or make -1 as ID variable default, on construct script check ID is 0 (or -1) if it is set new ID, if it not ID will simply stay the same :slight_smile: will be if you copy actor, ID variable may copy you will need to reset some how. Editor code of actor is hard to modify from blueprint sadly, C++ would be better place for that.

Generally engine uses pointers (pointer is a address in memory which points to the object data in there) as a unique identifier, as UObject as never hold directly in variable, so blue pin is identifier and it reason why you don’t see unique numeral IDs. If you see ID like in “Get Player Controller”, it uses array index of found PlayerControllers as a ID. Maybe playing around with array (since you can check if it contains specific element) is good direction here

Thanks for the answer. I thought it would be much easier, just by using the construction script. Guess for now I’ll leave it alone and come back once I’ve gotten to know C++ a bit.