I want to spawn a blueprint within another actors construction script

What I want to achieve is some kind of generator. Let’s say I have Blueprint called “Wall” where I expose several variables like wall material etc in it’s construction script. So far, so good.

Now I want to script another blueprint called “Room” which creates a floor and attaches four of these ‘Wall’ blueprint instances with their exposed parameters. How do I do this?

I know how to do this, if I make a parent blueprint of the wall blueprint through inheritance. But I haven’t found a solution where the variables are exposed as pins in the editor.

Maybe “Ad Child Actor to Component” is not the correct node to use.

Any ideas?

This video looked promising, but I can’t get a reference to ‘SpawnActorFromClass’ in the constructor script…

So from what I understood you want to create a “Room” blueprint in which you will have 4 walls with their custom parameters inside to access in the editor, if that’s the case then you just need to create the Room class and a Wall class (not necessarily inherited), once you have that, in the Room header you add the amount of walls you want to (you could also have an array with as many walls you want) have as pointers to the “AWall” type with an UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Walls) on top, this way you will be able to see their pins in the editor.

Now in the .cpp you need to initialize and add these walls as components attached to your Root or any component you want, this way you could create a BP in the editor that inherits this “Room” class and you will be able to play around with all the components you just added. I hope this helps ^^

That is because you can not spawn an actor from the construction script. You should use the Begin Play instead as this is fired immediately after the construction script but before Tick. To expose the variable pins ensure you make each variable you want seen to be ‘Editable’. Now when you put the blueprint into the level via the editor, when you select the blueprint you will have those exposed variables in the details panel.

I can not valiate your Message, because I am using the Visual Blueprint Editor and therefore have no header file. But I’m pretty sure this would work in cpp