Removing single instance of a foliage actor?

Hey,

Let’s say I painted 100 trees using the foliage tool, is it somehow possible to remove only one of them during gameplay? I know they are combined to clusters to optimize draw calls, so I’m not even sure if I can access them individually. To clarify: I don’t want culling, I want to remove one specific object/instance or make it invisible + deactive physics.

I already looked into InstacedFoliageActor.h but I’m not entirely sure how to access a single instance or a “cluster” of them.

Any help would be greatly appreciated.

Did you ever figure this out? I’m wanting to be able to do the same thing.

Hey Hatur-

Unfortunately there is no way to reference an individual instance created by the foliage tool. Your best bet to get the type of result you are looking for is to use a static mesh or blueprint with the same static mesh component as your foliage. I believe this will give the appearance that you’re looking for and allow you to control the individual actor that responds to input.

Cheers

  • I agree that that would work to some extent, however won’t you be pretty severely limited by performance in terms of the number of items you can spawn since they won’t be instanced? It doesn’t seem possible to create a forest or anything major this way due the sheer number of draw calls involved…

I’m currently trying to overcome this same issue. I had originally though that you might be able to work around it by using instanced static meshes created in a blueprint, but it seems as if you may have the same limitation there in terms of not being able to get or store a reference to an individual instance of the mesh.

Is there any way of getting/destroying a single instance of an instanced static mesh that was created by a blueprint? That seems to be the critical sticking point for making something like this work.

To elaborate on my previous message, I was referring to using the foliage tool to create the mass number of instances you’re looking for and having a blueprint that has the single object you want control over rather than using the blueprint for all instances.

That being said, here is a quick work around that should do what you’re looking for. Basically this will store a reference to each instance as you create it, then you can use that reference to refer to the specific instance you want to remove.

, thank you so much for this example. Seems trivial now that I see it, but I was having a brain block it seems, hehe.

Glad to have been of help. Good luck in your project.

Cheers

Hate to be a bother, but I can’t seem to find the ‘remove instance’ node anywhere. I’ve got a ‘clear instances’ node that looks somewhat similar(?). I’m in 4.2.3

No bother at all. That is a limitation of 4.2 as that node was not introduced until a later version. The Remove Instance node as well as numerous other tools to help project development are available for use in the most recent version of the engine.

For your current project, without the Remove Instance node being exposed to blueprints your best bet would be to use foliage to create a number of instances of the mesh and then have a separate blueprint to control the functions of the single instance you want to change (or using c++). As for your engine version, 4.2 only had a single hotfix. Did you mean that you are on 4.2.1? I’m not quite sure what you mean by 4.2.3.

Hey, thanks for the answers, going to look into it tomorrow : )

When you say “use foliage to create a number of instances of the mesh and then have a separate blueprint to control the functions of the single instance you want to change” do you mean that you could access specific meshes that have been placed with the foliage tool? or that all meshes that you would potentially want to remove (or in my case burn to the ground) would have to be instantiated with a blueprint?

For my game I want to be able to burn or smash down trees, rocks, brash and houses (although the houses can be placed manually as there wont be quite as many of them).

I haven’t been able to find a way to access specific meshes from the foliage so I am assuming I would have to make a blueprint to mass spawn them instead then I should be able to access them through other blueprints. I don’t really know how I would do that though, has anyone else found a solution?

I am making a game where you play a dragon so I am really keen to have as much destructible stuff as possible to really make you feel like a big powerful creature. See a film of it here Unreal Engine 4 Dragon game prototype - YouTube

In this case it would be the later. Meshes placed with the foliage tool cannot be selected individually. In the large scale case you refer to, you may want to have a blueprint that has multiple copies of a mesh with their functionality setup. Depending on the uniformity of your environment (tons of grass instances for example) you can then use fewer BP’s to cover a larger area.

Cheers

I was able to get quite a ways using the blueprint route that you suggested by basically re-implementing my own chunking/instancing logic similar to what is in the foliage tool. Gotta say, it’s amazing how far you can get with blueprints.

if I’m spawning tree blueprints through a blueprint is there anything I should do to combine draw calls and save on performance?

I could probably ray cast down from a set number of random positions and spawn the tree blueprints at the hit location so that they all spawn on the ground and I could do even more at a time that way.

What I am doing is spawning instanced static meshes and then swapping them out for ‘real’ meshes on an individual basis if I need to do anything unique with that particular instance.

The instanced static meshes inside one blueprint will do a lot to reduce draw calls.

Excellent, thanks I’ll try this.

if I wanted to remove a instance of a static mesh I had created through blueprint when you hit it or deal damage to it how would you find the right one instance to remove?

Hey The Cheese Dragon-

I found the simplest way to accomplish that is to create a function in the mesh blueprint. When the damage event occurs, you make a call to that function that has it remove itself.

Cheers

Hi ,

If I understand you correctly you are suggesting spawning a mesh blueprint which reacts to damage trough another blueprint. This would indeed be easier but to save on draw calls I was thinking of using adding instanced static meshes, (which I think would be necessary considering the quantity I want) the problem is I cant add blueprints as an instance only static meshes.

my plan is to try and remove an instance when it is damaged and replace it with a blueprint that can react to the damage, i.e burn and fall to pieces.