I have an array of truck BP’s that is made at run time from spawn from class. The player picks number of trucks to spawn, then picks drivers with different skills for each truck. All stats for drivers and trucks are in one truck BP. My question is how to get array of the trucks that are spawned, and set the driver for each of them separately after they spawn?
You can try to use the “Get all actors from class” node which creates the array automatically. Then you can use a “for each loop” node, get every truck individually and set the corresponding variable in it.
Something like this but with your variables:
For some reason I don’t get the variables that way. I have to use a cast to BP node after loop to get variable from BP. Im using 4.5
Why dont you add the trcuks into an array in your game state when you spawn them. The can hold a reference and you can allways access them from anywhere by getting the game state and casting it to your game state instance (not to mix up with game instance, thats another story). The trucks can have a variable driver which has a setter method.
I deleted my post which was too much complicated and totally agree with JOHIsaac’s idea about using an array of truck type.