How can I place actors in a level using code or BP?

I would like to replicate the behavior of dragging an actor class into the level from the content browser or class list using code or BP. How can I do this?

I do not want to add components or child actors to an already placed actor.

What type of Actors are you looking to place? Blueprints can be directly dragged and dropped into your level.

-W

What I’m really looking to do is have an Actor spawn or take control over a set of other Actors. It’s important that I can still select each individual “sub actor” after they have been grouped under a parent actor, to change properties on them. For this reason I can’t use Add ChildActorComponent or similar nodes in BP, because they are then treated as one object.

If I manually drag out Actors I can use Attach Actor to Actor node in BP to get the behavior I’m looking for. So to answer your question it’s any generic Actor type that you can manually drag to the level like you say, but I want to do it from code.

From a different discussion it seems I have to create an Editor plugin to do this.

How about something like that?

This would not make the spawned Actors available to edit in the Editor I’m afraid :frowning:

Another way of asking this question is:
I want to drag 1000 Actors into the level from the content browser but I don’t want to do it manually. How can I do this with code or BPs?

We have an experimental feature called ‘Blutilities’ which is a way to add a utility to the editor using Blueprints, to do things like arrange actors in the level.

I wasn’t aware that you could do that. Good to know :slight_smile:

Would it also be able to spawn new actors? Regardless this sounds interesting. I will dig deeper into the subject when I get a chance, thanks.

The answer is you can’t, because you can’t spawn actors in the constructor, which is the only thing called when you place an actor in the level inside the editor.

I just made a simple tutorial to use the Blutility:

Great, thanks :slight_smile:

For anyone who might be looking to do this:

There’s a global called GEditor of type UEditorEngine. I don’t know all the classes who have access to this object but the Blutilities JamesG suggested do have access to it. This object has AddActor(), which seems to be what is used when you drag something from the Content Browser to the level. You need to supply the level to add the Actor to, I got it like this:

GEditor->LevelViewportClients[0]->GetWorld()->GetLevel(0);

Thanks everyone who helped me get there :slight_smile:

since the blutility doesn’t work in any of the recent release (4.7.5 4.8 promoted and 4.8 master (yes i am that desperate i have tested all of them :)))) could you help with some of the functionality in c++ so i could have an interface to run script inside the editor (something like the blutility but actually working )

i understand if you don’t have the time lead me to any helpful doc or tut and i will be greatful

thanks in advance