1016064 trees

Disclaimer: I’ve never coded C++ or in Unreal before, and I picked it up 5 days ago. So I might not be doing it correctly all the time. :slight_smile:

The blueprint is based on AActor.
I have a StaticMesh property where i set the tree mesh.
Then I create a UHierarchicalInstancedStaticMeshComponent and set the static mesh that was given in the property. I don’t think there is a difference if I use UInstancedStaticMeshComponent or the other, but UHierarchicalInstancedStaticMeshComponent is newer and supposed to be used with foliage (Someone said somewhere). But I’m not sure I get any advantages from it because I don’t know exactly what is different between the two.
Then I generate my FVector’s where I want to spawn trees, and for each I do HierarchicalInstancedStaticMeshComponent->AddInstance(transform);

Btw: I’ve made two blueprints so far. One for trees which is a lot like the one coming in 4.8. And one for foliage that has 9x9 tiles where the tiles “follow” the player around. I’m planning on using a tiling system for the trees also, so that I can spawn trees regardless if the world is 10km2 or 100.000km2

Here is a demo of how the tiling works.
The foliagegenerator has a minimum of 81 meshes (1 pr 81 tiles since it’s 9x9). Lets say tile row index 0 is at the top, and 8 at the bottom. If I move 1 tile-length up, the code moves the 8 row up, then the 7, etc. So the area is always center to the character.
Since all instances are added at start, all I do is move them around. I never delete or add new instances.

v=9B0pNcthFGI

Then I make it 7000 large in radius and make it spawn 100 meshes pr tile.

?v=peA4C-bHitA

Then I copy&paste it and make the new one 15000 large.

v=FD7oKp2IIwQ

Here is the exact same scene with a grass texture on the landscape.

v=G4xZ9IdKizQ