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

**URL:** <https://forums.unrealengine.com/t/bug-fbodyinstance-uinstancedstaticmeshcomponent-potential-bug-in-fbodyinstance-when-using-uinstancedstaticmeshcomponent/1371370>\
**Category:** Rendering\
**Tags:** Hierarchical-Instanced-Static-Mesh, constructors, Instanced-Mesh, unreal-engine, Collision, question\
**Created:** [November 7, 2023, 5:52pm UTC](https://forums.unrealengine.com/t/bug-fbodyinstance-uinstancedstaticmeshcomponent-potential-bug-in-fbodyinstance-when-using-uinstancedstaticmeshcomponent/1371370 "2023-11-07T17:52:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![argingras2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@argingras2](https://forums.unrealengine.com/u/argingras2)\
**Post date:** [November 7, 2023, 5:52pm UTC](https://forums.unrealengine.com/t/bug-fbodyinstance-uinstancedstaticmeshcomponent-potential-bug-in-fbodyinstance-when-using-uinstancedstaticmeshcomponent/1371370/1 "2023-11-07T17:52:30Z")

</div>

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/4/5c42c759150aab4b7111237d23892792f33a1a4b.png)  
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.
