SpawnActor with variables?

I need to Spawn a Actor while also defining the variables so already the construction script does things based on those parameters. How can I do that?

Furthermore I like to just pass all the variable parameters from the parent BP to the spawned Child BP. Basically I have tree branch BP with lots of parameters which can spawn a smaller child branch which should have the same parameter settings.

Hi Davision.

You can set any variable in a BP actor with an “Expose on Spawn” flag (in the details panel when the variable is selected in the BP editor) which will add a pin for a value to pass into it when using the SpawnActorFromClass node. Make sure you set the variable(s) “Editable” as well. The construction script will now have access to that value from the start.

As far as passing variable parameters from parent class to child class, that should already happen automatically as part of normal inheritance. The child will take on the default values of the parent. If they need to be changed in the child (i.e. have some non-default value) you can simply pass that in by making the variable exposed on spawn as above.

Thanks!

But with the passing of all parameters I mean the parameters that I set in the BP settings of the actor placed in the world, so that are not the default values I need to take over. Do I have to do that then manually for each variable/parameter with Expose to Spawn? Would be just more convenient to just pass all parameters instead of making that for like 20 variables.

In that case, you could, for example, expose an actor reference variable as well, to which you send the actor whose values you want to copy for the newly spawned one. Haven’t tried anything like that in a construction script per se, but I don’t see any reason for it to fail, assuming you give it a valid reference to a predecessor, so to speak, that already exists in the world. You would still have to get all the values and write them to the correct place in the new actor of course. Could be made easier if the parameters were in an array for example, then you could simply copy the whole array in one go.

Thanks, will give it a shot.

… you saved me with this … thanks !! … it works perfect ! … I`m spawning characters on the stage and need to give them a unique ID at the spawn time … I thou to figure it out by Event thou, but this, I mean your guide, is the key … : ) ,

I have a problem - and although this seems to be an old thread - I thought I might try. In theory this seems like the solution for me, but I’m setting the class in the spawn actor with a variable that’s set in the HUD by the player clicking a button. When I plug that variable in - its associated variables dissapear. I guess - because it’s not clear yet what it could be. How do I pry the variable from either the class variable that’s been set by clicking a button before the spawn - or - the object that’s been spawned after the spawn? Is it impossible?
(I did it like this because I just couldn’t find a way to cast to my widget and pry a variable from there)