Setting Variable on SpawnActor

Could you clarify your question?

Expose on Spawn is for the containing class. If your class spawns or references another class that has an exposed variable that you want to change on creation. You’ll have to make another variable on the Spawning class that is exposed, and set it manually to the other referenced actor.

In this case, spawn function cannot take exposed variables, because spawn class is kinda unknown. I think it works like spawn class is AActor, or something like that.

You should specify spawn class in spawn function, or cast to desired class after object spawned, and set variables you want.

In that case I’ll have to find a workaround.

I can’t cast to the object since that would constrain me to a single class BP

Then no, you can’t expose that pin on the Spawn function, because the compiler doesn’t know which Actor will be spawned. You could create specific functions for each class grouping of actors that you were to spawn, these would then spawn the actor with the specified pins.

Hi

Is there a way to set an exposed variable on a SpawnActor function that’s class is being referenced by another variable within the blueprint?

http://i.imgur.com/F7FgUR6.png

here is the variable in my actor I want to spawn

http://i.imgur.com/BbWmKRV.png

1 Like

Ok

In BP1 I have a reference for the class I want to spawn which is BP2.

I have to spawn BP2 from BP1 using this actor reference and set the exposed variable on BP2.

the usual way of just reference the actor directly on the function wont work because the reference object changes all the time.
The reference is also set automatically based on other inputs. There cannot be any manual input here.

Hello, did you find a workaround ?

I did in fact find a workaround, I forgot to update this question. I made a blueprint interface event then called that using the newly created actor and passed my variables through that. Will update later with pics.

ok thanks :slight_smile:

You have to mark the correct answer in this thread, please. Or add a new post and mark it.

Hey Jimonions, Thanks for posting your workaround. I was having the same issue but I still can’t Understand how you connected the variables of your spawned blueprint to new ones.

Blueprint Interface Events - BPI’s do not require a specific target.
Since the spawn actor node has a variable going into the class reference input it cannot output a suitable reference that we can trigger an event from and pass through variables that way.
By calling this BPI event I can just hook up the spawn actor reference to the target input and that will do exactly the same thing as a regular event provided the spawned actor also supports that BPI event.

if you need more info on what BPIs are there are numerous tutorials out there.

Here you go

Set a variable expose on spawn, this will create an extra node in the spawn option. For instance, I use a data table row to set the variables:

1 Like