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

I want to spawn actors for a grid that can be edited at “editor” time. Since i cannot do this at construction of the “game board” blueprint, where am i supposed to do this?

1 Like

I’m having the same problem. I assume you’re not content adding components to your game board, but you wish to access each grid tile in the Editor.

Since it is possible to create actors inside a component in the construction script (this is what the Add ChildActorComponent node does), I’m wondering if it’s possible to create the actors inside a component and expose them to code that moves their outer from the containing scenecomponent to the level. I haven’t tried this myself but it’s currently where I’m at in my experimenting.

SpawnActor method is not available in the Construction script. Do you know of another way to do this?

What event would you use to trigger the spawning of these actors?

Then the actors would not be available to edit in the Editor

Well me personally would like to the option to change any properties on them like they were individually placed actors. I don’t know what joessu would like to do but I imagine it’s something similar.

1 Like

Copy and paste of actors helps

a grid of actors

Well one example would be a village where you would want to spawn a number of buildings procedurally. You want to be able to move the whole thing as a whole or quickly place a number of these at different places. After they’re placed you might want to go in and change gameplay related properties like what kind of building this is (e.g House / Factory / Farm).

Are you doing this without starting the game in the editor? If so I will definitely try this as soon as I get home.

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.

1 Like

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.

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.