How to get gameobject

Guys,

I have been looking for a way to get an actor from the world. There are many ways to spaw and store the actor after it is spawned. However, I want a way without spawning. I want to get the actor which is already there. I assume there might be many ways like with tag or name. Can you guys show me those?

Additional Info: I want to get them in my custom PlayerController class.

Thanks in advance.

Here is a wiki article that describes how to iterate through all the objects or actors in a world:

Object & Actor Iterators

Do I have to use the iterators only?

I’m assuming that you want to get player actors if yes, you can use “Get Player Controller” BP function then try to cast to your player controller.

Oh no no :slight_smile: I do not care about the controllers. I want to get actors. However, I do not get all the actors at once. I want a way to get a specific actor immediately. For instance, I look for a method let say ‘GetActorWithName(String)’ which returns the exact actor from the world. I do not want to go over every actor in the world.

I’d suggest staying away from iterators and implementing your own system to do this properly, e.g. have the actor post to some container object that holds information on all the actors you are interested in, and then use that container to find what you’re looking for. When I see all object iterators in code, it generally makes me think that the code wasn’t well designed. Just my two Zimbabwean dollars though.

Actor iterators are much faster in UE4 than they were in UE3, but you have valid points that there may be better ways to “find/associate” your actors with each other.

You can use the iterator to only get actors of a specific class, and you can certainly use GetName to find the one you are looking for.

Maybe a little more context would be helpful.

Ok. As far as I understood; This is the only and best way unless you do better :stuck_out_tongue: Thx.