Yesterday, 12:45 PM
Hi, for convenience I moved Obi from Assets to local package and from that moment I encountered very strange bug, I am still not sure if this has been caused by pure random chance because script execution order changed after moving them, or I modified my scene, but in any case there is bug in collider world.
Observation - when new prefab is instantiated into scene (and old one is removed), then for some reason ObiColliders are not registered properly and in result there is no collision with them, unless reenabled.
Investigation - it looks like collider world is destroyed (and also solver implementation and everything else) when there are no colliders to manage. However it does not take into account colliders that should be added during next update. I think that Collider becomes enabled so it registers itself in collision world, but because other collider become destroyed/disabled, then it runs various checks, including DestroyIfUnused() and because number of colliders drops to zero it gets destroyed, but it does not care that there are colliders waiting to be registered! Also actor needs to be reset and is disabled for split of second so Teardown() is called and whole simulation dropped for no reason.
Is adding additional check 'collidersToAdd.Count == 0' in the if statement below valid way to fix this problem?
Observation - when new prefab is instantiated into scene (and old one is removed), then for some reason ObiColliders are not registered properly and in result there is no collision with them, unless reenabled.
Investigation - it looks like collider world is destroyed (and also solver implementation and everything else) when there are no colliders to manage. However it does not take into account colliders that should be added during next update. I think that Collider becomes enabled so it registers itself in collision world, but because other collider become destroyed/disabled, then it runs various checks, including DestroyIfUnused() and because number of colliders drops to zero it gets destroyed, but it does not care that there are colliders waiting to be registered! Also actor needs to be reset and is disabled for split of second so Teardown() is called and whole simulation dropped for no reason.
Is adding additional check 'collidersToAdd.Count == 0' in the if statement below valid way to fix this problem?
Code:
private void DestroyIfUnused()
{
// when there is no data and no implementations, the world gets destroyed.
// don't check materialHandles.Count == 0, as these are scriptable objects and may outlive the world.
if (colliderHandles.Count == 0 &&
rigidbodyHandles.Count == 0 &&
forceZoneHandles.Count == 0 &&
implementations.Count == 0)
Destroy();
}
