[Bug] [FBodyInstance] [UInstancedStaticMeshComponent] Potential bug in FBodyInstance when using UInstancedStaticMeshComponent

argingras2
Tue, 07 Nov 2023 17:52:30 +0000
Rendering

Issue:
In FBodyInstance::SetCollisionEnabled, if the value of FBodyInstance::CollisionEnabled actually changed since its last call, the function UActorComponent::RecreatePhysicsState gets called. In turn, that function destroys the physics state before recreating it.

As a result, the body instance gets completely recreated and we call its constructor, where the value of FBodyInstance::CollisionEnabled gets reset to its default (QueryAndPhysics).
This effectively means the call to FBodyInstance::SetCollisionEnabled did not work as the value of CollisionEnabled will always be QueryAndPhysics before and after the call.

I believe this might be an issue only when calling FBodyInstance::CollisionEnabled directly instead of UPrimitiveComponent::SetCollisionEnabled like we usually do. This is something we need to do for UInstancedStaticMeshComponent if we want to only disable the collisions for a single instance in the list.

Solution:
A potential issue was to avoid the recreation of the physics state in some cases.
In our game, I added an engine modification:

Essentially, I added an optional argument that drives whether or not to call RecreatePhysicsState. I think we would need a better fix but this is why I am requesting help here.

Thank you in advance.

1 post - 1 participant