I’m spawning an Actor BP (static mesh) at random locations. I would like to have random variants, specifically different rotations on Z-axis for every spawn.
Currently, I’ve created child classes of my BP, manually added different rotations and I’m spawning them by using switch on int + random integer in range. This essentially works but it is not REALLY random + I would have to add many many more variants, which would take time and result in spaghetti code.
Hi man,
You dont need a child class ,
Get your ActorBlueprint, and add him a variable for the amount of rotation, use the tick event for rotate the static mesh of that amount.
You generate a random location, and then spawn the actor there.
The spawn actor will return the reference of the actor, pin out and set the variable of the rotation of that particular actor, using a random float in range.
Repeat all the times you want.
If the random location is really random you can make a location using random- float in range.
If you have specific points where you want to spawn, and you want to choose one randomly:
You can collect all the locations in 1 array, and then pick a random number , min 0 and max the lengt of the array -1