Download

Interact with foliage at run-time (Cut down trees, remove foliage, etc...)

Hey guys, a lot of you have been wondering how to interact with foliage (Cut down a tree, remove a plant, etc…) during run-time, so yesterday I did some experimenting, and got it to work :slight_smile:

I’ve made a tutorial, and essentially what it does is let you turn any given foliage instance into an actor, which will then allow you to manipulate it as if it was any other actor. In my case, I turn trees into actors, and they fall down as if I had cut them, I also gather wheat that I have placed with the foliage tool. Later today or tomorrow I will also be posting a tutorial on how to place foliage during run-time with all of the foliage optimizations. The video is ~35 minutes long, but try & watch all of it.

https://youtube.com/watch?v=F_RS1vlBYXI

Now that you can remove foliage, do you want to be able to place it? Check out my 2nd tutorial here: https://forums.unrealengine.com/showthread.php?75913-Place-foliage-at-run-time-tutorial

Just about to watch it now, thanks in advance. :smiley:

Very usefull! Would the process be the same with the new procedural foliage tool and grass type? that would be amazing if you got it to work with those!

I haven’t used procedural foliage, as long as it uses instanced static mesh components, it should work. I will try right now. I’m glad you like it.

Edit: This works with the procedural foliage spawner. For procedural foliage spawner, you still need your MyMesh, and your MyMesh_BP, and then you just need to make your FoliageType and select the MyMesh.

It won’t work with the landscape grass which is spawned by material because you can’t hit these with a trace, they have no collision at all, unfortunately.

If this grass has some sort of static mesh you can open, then you can generate collision and set it up for line traces.

The the grass ignores the collision from the mesh, for performance reasons I guess since grass generally never has collision and collision is expensive for such amounts of grass.

I’ve just set it all up and it works great! Setting a time to live on the actor blueprint for the trees prevents the clutter. Now to figure out how to respawn the tree again.

Yep, I have made a BP for spawning them again while keeping the performance of foliage, I just want to fix it so that the trees align to the floor so that I can demonstrate that in the tutorial.

Edit: Here is the tutorial for spawning/re-spawning foliage: https://forums.unrealengine.com/showthread.php?75913-Place-foliage-at-run-time-tutorial

This video tut is awesome - My personal opinion for getting rid of excessive amount of actors. Use a delay and then a Destroy Actor.

Going to implement this tutorial in a minute and give it a shot. I will report back with my findings :slight_smile:

Yeah, I’ve done some testing with delays, and it works fine. I’ve also looked into having the actors fade away, but haven’t found anything. The only problem with this tutorial is that once you stop the game, the foliage re-appears, which shouldn’t be a problem for many people. It is possible to save & load, but it usually isn’t worth the trouble. Besides, if you have a big forest, there won’t be much difference whether or not a tree is gone or not. Be sure to check out my 2nd tutorial for placing foliage.

Edit: Loading & saving may be easier than I thought, I will look into it and report back.

Thanks for taking the time to make a tutorial. It’s a good setup and easy to use.

Just to add to the destructibles part though. Ideally using planes as destructible assets will not give good results, this is mentioned in Nvidia’s documentation. Destructibles work best by having a 3d closed mesh. If you were to fracture a tree mesh that wasn’t a closed mesh at the bottom of the trunk you’ll get a fracture in most instances without issue, but there won’t be any generated interior geometry.

You mention at one point that the collision doesn’t look right, with the “floating” pieces.

You can view PhysX collision by entering the console command “PXVIS Collision.” With this enabled you can see why the collision is not right. With Destructibles there isn’t custom collision generated or a way to adjust the collision hulls like static meshes, so when the chunks are created a single convex hull is generated for each chunk when the mesh is fractured. The convex hull will not be a tight bounding collision body so it can leave the odd results of floating pieces.

Just wanted to mention these things.

Thanks again for the tutorial! :slight_smile:

Alright thanks for letting me know, I am glad you found the tutorial easy to follow :slight_smile:

Amazing tutorial! Really glad to know this is possible. Is there any way to fix the floating actors at all then?

Are you referring to the destructible mesh pieces floating?

Yeah when the tree pops up a little when the actor replaces the instance, is that fixable with different collisions or some other way?

Just spawn the tree at trace location + vector 0/0/-20 and the tree is in the ground then.

Yeah Cyber, that is a quick & effective work around.

Any tips on getting this to work with a procedural foilage spawner volume? I’ve tried casting into these classes from the hit primitive. It works fine for painted on iSM obviously but not with the hierarchaliSm that the foilage spawner seems to use.

http://i.imgur.com/hcxGUq8.png

Maybe I misunderstood your problem, but this should work with procedural foliage, everything should remain the same as in the video. I am currently able to do this with trees from a procedural foliage spawner. Make sure that the volume itself is not blocking the trace by turning off the volume’s collision, also make sure to turn on collision for your foliage type. If this is not your problem, reply back here.