How to create interactive foilage? Cuttable/Regrowable grass and trees.

What is the theory behind making grass that you can cut and will grow back after some time and trees which you can chop down and remove the stumps?

Basically I would like to know what things I need to use and do to create plants that have various states of existence and remove them altogether.

Thanks for any help.

Well basicly you could create different models for everything, lets say there is one when the grass is fully grown, second when it’s half grown, and third when it’s cut. You can create animation to cut the grass and actually when you cut the grass, you replace the fully grown model with the not grown model. And after, say, 5 minutes, you replace the not grown grass with half grown, and after 5 more minutes you can replace it with fully grown.

Hey there,

Actually I wanted to know something similar so I decided to join this thread. I’d also need some trees that can fall when let’s say a tank passes by. Regrowing and bending grass when running around should also be possible. Also trees and grass should react to wind in the engine. As far as I know it’s possible to use the wind with the painted trees and grass using the terrain editor.

But what about cutting/falling trees, regrowing and so on ? Can I use the painted trees or do I need to use my own instanced tree-blueprints that can handle all that ?

This would be the simplest way. The hard way (and also more technically expensive) would be to generate number of vertices based on age. Adding more and making it grow, changing the model using a dynamic natural growth algorithm for, say, trees.

Wind is physics and can act on the model. I would look at the source code for the terrain painted stuff and how it reacts to wind.

Some old but great articles on how to get started with this can be found here:

Essentially, for growing things, you are looking at time lapsed procedural meshes.

I believe you could achieve live growing with animation morph targets, but it may end up being expensive, even if you are using intervals.

[video]It Grows! - YouTube

What about cutting/falling trees ? If I use the Landscape Editor to paint vegetation would I be able to interact with every single tree ? So lets say I play a tank and drive through the woods and once I drive over a little tree its falling ?

Hey Ice,

As I understand it(and my knowledge on the landscaping tool is limited), but it essentially just places static meshes around the world in the defined area of the brush. So one possibility is creating custom object, that have different stages and have animation montages that tie the stages together.

So for Example you have a grass class. Well you could have 5 different basic meshes; one for 0%, 25%, 50%, 75%, and 100%.
Then basically have the grass determine if it needs to grow to the next stage, and use a simple animation to transfer from one stage to another.

So lets say you cut your grass, so it would be at 0%.
Create a function that basically is bool canGrow(), and pass in any parameters; like how many times its been run over or passed by. How much time has passed in the game world, or anything that you would want to influence it.
Then let that be called either on the tick or every x seconds.

Once you have that running, and assuming it calls the function and we can grow; check which stage it should be at. So, lets say we are at ~24% and about to hit the 25%. Well we keep playing the animation at the grow rate, and when we hit the 25%, remove the old 0% mesh, and stop the animation for it. Then spawn in the 25% mesh at its location and call the appropriate functions and have the animations start running.

That is how I would imagine it would work for making grass grow and being influenced by the players. Apologies if this sounds like rambling.

@: sorry for the late response! If I would use your approach, I could not place the vegetation via the painting tool first, right ? Because I heard that it’s not possible to get a reference of a single mesh via code if it’s placed via the painting tool ?

Hey, you can do interactable foliage by overlaying multiple instanced static mesh components (ISMs) and only showing one at a time. Its a bit difficult but doable. You can combine it with the foliage tool. If you check out InstanceFoliageActor.h you will see it manages ISMs, one for each mesh in your foliage settings. You can iterate over those and spawn alternate meshes at those positions and rotations. Then only show one at a time by hiding the others.

Thanks for the help! So it would not be possible to place all the vegetation with the landscape painting tool IF I want to have different animations for each tree and so on ? For example a falling tree when passing by with a tank ?

To combine animations with Instanced Static (!) Meshes you probably can try hiding the instance and spawning a temporary skeletal mesh actor in its place to handle the animation.

Ok. Do you know if its possible to get a reference of a painted tree to do so via code or blueprint ? Or do I have to place them manually one by one ? All I want to know is if I can use the painting tool for the vegetation or not. Because I heard its not possible to get a reference for specific painted trees for example.

Thats what I’m talking about: Removing single instance of a foliage actor? - World Creation - Epic Developer Community Forums

Seems like you can either use the foliage tool to paint vegetation, but without interaction. Or create own blueprints and place every single mesh instance by hand, but have the ability to add animation states and so on, right ?

Yes, you can get a reference to trees painted with the painting tool. You can find the InstancedFoliageActor, the actor that the editor stores all foliage instances in, using a TActorIterator<AInstancedFoliageActor>. Find the instanced static mesh components within that actor.

Another note: as of 4.8 if you want to use foliage C++ classes (edit: like InstancedFoliageActor) you will have to include the Foliage module. To do this, find your Source/MyProject/MyProject.Build.cs file and add “Foliage” to the PublicDependencyModuleNames list.

Wow thx! So I could reference one single tree I had collision with, remove it and replace it with an animated instance of that tree, play the “fall” animation and then create another instance again on that position after a few seconds ?

good info thanks, necessary for my near future plans :slight_smile:

how do you do this in blueprint?