Hey everyone. I’ve run into a problem that I couldn’t solve. Thus I hope anyone in here has some idea how to approach it
I want to have a character ability that can remove certain foliage types. For that purpose I’ve implemented a new component (let’s call it MyCustomFoliageComponent
) that inherits from UFoliageInstancedStaticMeshComponent
and is set for the corresponding StaticMeshFoliages
as ComponentClass
. If the character performs its ability I detect affected FoliageActors by checking for MyCustomFoliageComponent
and perform a combination of MyCustomFoliageComponent::GetInstancesOverlappingSphere
and MyCustomFoliageComponent::RemoveInstances
. This works quite well.
The problems occur when I try to make its state serializable/compatible with save games. I have a serialization framework and a corresponding interface that MyCustomFoliageComponent
implements. The interface has a OnLoad
function that is triggered properly (e.g. after a savegame is loaded). And when I check the number of instances with GetInstanceCount()
it returns the correct number of instances (thus the count after some instances have been removed). But there are/were two problems:
Solved part: Visually even the removed instances have been visible at this point. Thus I’ve looked into the implementation of RemoveInstances
and have notices some code that helped to solve this issue. Adding the following piece of code to the OnLoad
function solved the issue.
if (bAutoRebuildTreeOnInstanceChanges)
{
BuildTreeIfOutdated(true, true);
}
MarkRenderStateDirty();
This is just FYI in case someone has a similar problem.
Problem: Even if the code above fixes the visual problem… The colliders of the corresponding removed instances are still there. I’ve tried out some functions (e.g. UpdateCollisionFromStaticMesh
) but it didn’t help. Now I am stuck and don’t know how to trigger the collision update for the underlaying foliage mesh properly. Does anyone have any hint or idea how to solve this?