Best way to generate lots of trees without slowing down computer

I have a blueprint I call a TreeSpawner where you can customize the length and width of your level and it randomly generates trees in the area but my issue is that it seems to be too much for the computer to handle and the game gets incredibly slow when the map size is still relatively small.

The trees are fairly low poly and untextured. They are being added with the AddStaticMeshComponent node, I also added the SetMaxDrawDistance node connected to the AddStaticMesh but that barely helped at all.
I looked into using instances or hierarchical meshes but I didn’t fully understand the differences. I’m still quite new to the program.

The meshes need to have collisions enabled because the player will be walking around them, whats the best way to do this? I can provide more information if you don’t fully understand what I’m saying, my current method is just slowing down the whole game way too much.

type or paste code here

There is integrated tree placing tool.
But if you want to place trees using blueprints you should use mesh instancing. There is “hierarhical instanced static mesh” component. Add it to your bp actor. Then set tree mesh in this component. Then spawn instances of this mesh using bp node Add Instance. And set manually instance transforms. This approach used by default unreal engine’s foliage tool.
Well… it will be better to see video about instancing first
here i found - UE4 Optimization: Instancing - YouTube
example in video shows work with stones but it will work with trees as well.

And i should say that there is integrated way to procedurally spawn foliage. You just need to enable it in Editor Prefrences. Then create blueprint and fill it with trees.
here is another tutorial about this - Procedural Foliage in Unreal Engine 4 | UE4 Tutorial (2020) - YouTube

Also if you have plans to … chop down trees then there is way to get exact instanced mesh no matter from procedural foliage or from blueprint instanced foliage.
In Hit Info (after line trace for example) you can get Hit Index parameter with index of instance that you hit. Using that index you can get that instance transforms, hide that instance or do animated things like tree fall down.
And ofc there is another tutorial about it - Cutting down Foliage Trees | Unreal Engine 4 Tutorial - YouTube

2 Likes

Thanks dude, this is just the kind of answer I was hoping for. I have to use blueprints and am avoiding the foliage tool because the idea is that it randomly generates every time you play.

An extra thanks for adding the tutorial links. You are a credit to your species.

2 Likes