Each actor have number

I want to have for each actors in the level to have a number or an ID

Try to get all actors of class and put them into map variable


UEgaaoc3

1 Like

The above will not work and is potentially quite disastrous.

May not be as bad as I thought unless it’s used in a specific way. But then it’s on OP not on @Yaklakootmaa2


The int should be in the actor, give each actor an ID first (this can be done with Get All) on then pull it out of the array element and push it into the dictionary.

Interesting to know why it won’t work and why it will be disastrous?

Get All does not guarantee element order. I mean, it really depends on what you’re going to with that information later.

I want to have for each actors in the level to have a number or an ID

With the above script the actors in no way know their own IDs. They’d need to query this container.

Didn’t know that. I think it doesn’t matter if do it once it might work

1 Like

Try it in PIE and then in Packaged. Again, it depends on what really is supposed to happen to the data later. Risky stuff.

Simply ask the gamemode for a number after creating the acto
Alternatively let the GameMode always create the actors instead of creating them anywhere in the code and handle everything in one place.

I believe the scenario here is that actors are already in the level. But I often assume too much. :expressionless:

1 Like

Thank you, will keep in mind that. I’ve never used this approach but thought about that in some cases for run-time operations.

1 Like

So. Why don’t you loop over them in the GameMode and set the number at the start?

I seem to assume to much, too…

That’s what @Yaklakootmaa2 script is doing. Not sure what this is going to be used for, a red flag popped up for me. When I see Get All + IDs, I panic. I panicked.

No. He loops and packages them in an array. I would simply fill a variable in you actors class reference.

We don’t know what the thread creator wants to achieve at the end so we can only give you ideas.

Seconded - that’s what my first comment suggests.

BUT: you must ensure that you never use Get All again to try to identify those actors. Every time you call this, you may be getting different order.

  • get all → give actors IDs → push into the Map, never touch Get All again, use Map only from now on.
1 Like

Each object/actor already has a unique, built-in “name” which you can use depending on your use case; “Get Object Name”.

It’ll potentially save you the hassle of looping through everything.

And also he might use the tag system to don’t loop through everything

thanks you