Get Actor By Id

Hi.

Is there something like in title, or one has to iterate through all actors in world (or all actors of class in world) every time, i want to get one specific actor?

Thanks,

L.

Hey lukas84,

There is not currently a way to get an Actor by its ID, though that seems useful and I will put in a feature request for it.

For now, you can use GetAllActorsOfClass and identify actors by type or some other means (for instance, ActorHasTag), but that is slow for scenes with >100 actors. A better practice is to keep track of actors you spawn in a list and search that small list when needed.

Hope that helps!

Hi , ok, thank you for your explanation :).

Yea, as for original idea getting by id, it would be also good getting by property so i can define new property, eg X. and if it is number, get like where x < y etc. However, thats in final probably always iterating through all actors anyway (even in UE embed function).

But even getting one exact actor would be good i guess.

Have a nice day.

L.

What is an example where you want to find an Actor by ID, rather than setting a pointer to that Actor in editor (using picker)?

Where your actors are dynamically spawned from a database back-end, and you are using network communications to identify an action for an actor that another user via network has performed. Think small-scale MMO, a forest with 3 squirrels. Person #3 is fighting Squirrel #2. Without being able to assign/identify actors by ID, this gets very cumbersome. (reinventing wheel, when there’s already a lookup list built in to editor/level, we just can’t access it)

If you are using UE4 networking, you can just replicated a reference to squirrel! If you really do need to find an Actor by name, you can use FindObject function.

Hello i cant find FindObject function is this function renamed in blueprint ?