How can I spawn a random static mesh on a projectile's collision?

I’d like to spawn random tree meshes when my projectile collides with the ground—how can I spawn lots of random trees?

So far I’ve only figured out how to spawn a single mesh, over and over using on Component Hit > Add Static Mesh Component.

Is there a way to pull randomly from a bigger list of say 10 trees so the resulting treeline is randomized and not always the same tree?

Bonus question #2: is there a way to randomize the rotation/scale on the spawned trees?

Bonus question #3: is there a way to have the tree “grow” from 0 to 100% scale when they spawn?

Thanks for the help.


Hey there.

First of all, since the tree has functionality, I would create a blueprint for the tree and add a static mesh component.

Now, instead of adding a static mesh component you spawn an actor of the class you just created. Here you can set the location and rotation as you like, and even make it random. Make sure to plug the location from your Hit event, otherwise the actor will spawn on a fixed location and you don’t want that.

For the random tree part, you can use the get random array item node and set the static mesh to a random item from an array of trees. You can create this function on the construction script or you can fire it through the Begin Play event (idk which is better for your case), so it runs when the blueprint is spawned.

Finally, you could use a timeline to simulate growth:

Note that there are more things you need to do to make it work properly, this is just the general idea you can follow. If you need more clarification feel free to ask. Good luck!

2 Likes