I’m using a BP Actor to spawn multiple instances of another BP Actor.
Right after spawning a Rotator Variable (Belt Rotator) is passed to (set in) the spawned Actor by the Cast to… method.
The Rotator would be used once in the spawned Actor to rotate a Vector Variable (Belt Speed Vector) and set it into another Vector Variable (Location Delta).
When I try to execute the rotation in the Construction Script or at the Event BeginPlay node, the vector is just simply not rotated. I mean that the original vector is stored in the new variable without any change.
However, when I execute it at the Event Tick node everything works fine.
I’m more or less OK with this except for the unnecessary execution at every tick.
Is it a bug or a feature? Am I at fault not fully understanding the Construction Script and Event BeginPlay behavior?
Any ideas, notes, comments or observations on this issue?
Where do you set Belt Rotator?
It’s set together with another variable in the BP Actor that spawns this BP Actor, right after the spawn node by using Cast To … and Set as the freshly spawned Actor.
Both variables are set correctly, I believe, since both of them working properly from the Event Tick node.
Just as I’m writing this it started to clear up a bit perhaps…
As the engine executes the SpawnActor node it creates the new object that includes running the Construction Script and the Event BeginPlay nodes.
When this process finishes it returns to the next node right after the SpawnActor node so the two Set nodes execute only when the Construction Script and Event BeginPlay nodes are already done.
This might be a logical explanation.
Perhaps I should read those variables from the spawned Actor from within the Construction Script… what do you think?
Mark your Belt Speed Vector and Belt Rotator Variables in the spawned Actor (Treadmill_BeltSection) as Editable and Expose on Spawn. After that you can pass the values you want to use in your beginPlay and constructionScript directly in the spawnActorFromClass node (in my Case it’s a ThirdPersonCharacter, yours would be the Treadmill_BeltSection). If the new variables don’t show up after compiling, just right click the SpawnActor node and chosse RefreshNode
Thanks for your answer.
I’ve just discovered it too for myself that it should work for this case like that.
My only remaining question is how to handle a similar case when the spawned BP class may vary.
I can then create an Object Reference Variable in the various BPs to be spawned and pass a self-reference from the spawner BP the same way, so then I can read any variable from the spawned BP, I guess.
Do you think it can work for such cases like that?
Hey Joe, glad I could help. Yes that will work and that would be also the way I would go. I guess there is a cleaner way to do it, but - depending on the size of your project - it is noting wrong with that. What I would recommend, use an interface and a (interface) function in your first Actor (the one which spawns the others) to return the Values to the Clients (not direct variable access from children), so you don’t have a hard reference from your “childs” to the “parent” actor. If you ever need to exchange the parent or migrate the childs to a new project, you will be thankfull just use a normal actorRef variable type in your clients and check with “doesImplementInterface” and call the function to retrieve your values.
But I’m curious, if you feed in the Class to the spawnActor with a select, and all that clients have the same parent (which maybe holds all the common variables the clients can overwrite) - maybe UE is smart enough to recognize that … but not sure, just an idea
Hey Adnoh, thanks for the tip.
I really need to educate myself on the BP Interfaces they seem very useful.
Do you believe that they are available before the Construction Script executes?
The spawning is triggered by a collision box and, although there is no real need for that, the Class is fed from the Other Actor pin however only one Class is spawned from there.
The colliding Class is checked beforehand by a Cast to… node.
yes they are available. an interface is simply a hull or a contract between several classes for implementing/providing a function/event with a given/stanarized name and parameter list. so in other words, every class which implements interface foo in which is declared something like function int bar(who: bool, knows: string) - does exactly provide this - a function named foo, returning an int and having too params.