Can't Spawn Actors in Construction, so now what?

Ok lets start with just having a Village BP. If you drag this out in the Editor it’ll procedurally place a bunch of meshes for buildings around. This makes it quick and easy to create “villages”. This is also not hard to do with ChildActorComponent or StaticMeshComponent.

The problem with this is that the Village Actor will act as one object. You can’t select one of these ChildActors inside the Editor and tweak it’s properties.

If you on the other hand drag a bunch of House BPs out in the world randomly, you can have a different Village BP look for these and use Attach Actor to Actor to attach them to the Village Actor (ie. itself). If done this way you can still select each House individually, but you can also move all of them with the Village Actor. This is what I want, and I think joessu too, but the size of the proverbial village may be too large to effectively drag each house out manually etc.

Excellent, now we’re getting somewhere. I will look into this when I get a chance, thank you.

Seems weird to me that actors can’t be spawned in the construction script, even if added as children. I noticed that child actors can’t be selected in the hierarchy either, which is interesting.

Plugins? really? I think i would just modify the unreal source to allow spawning actors at construction time. Maybe inherit from a class that tags the actors that are created and deletes any actors of that type anytime construction is rerun.

Sure you can edit the engine source code. It would be better to make a plugin and then you could easily maintain it from engine version to version, and you could share it easily, plus you will most likely want to add more features.

Have you found a solution so far? I have the same problem here

We worked around it. Luckily our game is small enough to warrent manual placement of actors. Basically we have an array of actors that we set, and then the construction script loops through and positions them accordingly.

So to be clear, no we do not have a solution for this, but managed to not need it.

Can you post some skeleton of your solution to help people with their constant struggle?

Imagine that I need a picture made of that Cells with different colors. Something like pixel art. Should I do it by hand cell by cell?

If you’re really really sure you want to spawn actors in a construction script (you’ll have to manage their lifetime yourself), you can put this helper function into a blueprint function library:

UFUNCTION(BlueprintCallable, Category="Actor|Utilities", meta=(Keywords="spawn actor"))
AActor* SpawnActor(UWorld* World, UClass* Class)
{
    FActorSpawnParameters fp;
    fp.bAllowDuringConstructionScript = true;
    return World->SpawnActor<AActor>(Class, fp);
}

You can’t use this code for a BP Function, because BP doesnt allow you to set the world parameter, it just wont save the bp.
What you have to do instead, is to get a reference to an Object, from this object get the world. Replace UWorld* World with UObject InputObject, and World-> with InputObject->getWorld()->

Same problem here, this is really annoying. I need this to switch between different lights attached to a blueprint in the editor.

Blutilities have come out since this was posted… which is what we use now. At the time this was posted there was no way

This worked for me!!! This is the answer ive been looking for thank you!