Search Unity

Character Controller extremely rarely ignoring collisions

Discussion in 'Physics' started by Haze-Games, Aug 25, 2020.

  1. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    190
    Hi all,

    I've come across many threads about this issue, but they are all 3-10 years old. I'm creating a new post again because this issue is still happening, and has been for a while:

    The Character Controller, works 99% of the time. At some point, a random collider (any ground or obstacle) will start to be ignored by the Character Controller. When this happens, it won't ever collide with it, ever, until the next scene reload.

    I have found absolutely no way to prevent this from happening, but here's what I noticed:
    • Never been able to reproduce in the Editor, seems like a build-only bug (very problematic to reproduce and fix)
    • Seems to happen less often when "Prebake Collision Meshes" is disabled
    • Can happen with Box Colliders and Mesh Colliders, but seems to be much more often with Box Colliders (could simply be that I mostly have Box Colliders)
    • I'm talking about static colliders here: they are never moved, don't have a RigidBody. I do disable them from time to time, but this issue happens with colliders that are never moved nor disabled throughout the game, so doesn't seem to be linked to disabling and re-enabling a static collider later on.
    • This bug is rare and random: could never happen in session of 5h, or twice in 10 minutes.
    • Adding a kinematic rigidbody to static colliders seems to reduce the chances of it happening, but it isn't a viable solution to make every single wall a kinematic rigidbody

    Additional info:
    • My collision layers matrix looks fine and I double-checked it many times, as it works most of the time and only fails selectively on random colliders
    • The character controller does not have a rigidbody. I understand it shouldn't have one.
    • None of the colliders, nor their transforms / parent transforms are negatively scaled

    Has anyone else encountered this before? Any help, suggestions or ideas would be appreciated. I'm trying to come up with a repro project for this, but for now it's only just working fine, and you'd need to test the repro project for at least 1h for it to happen :(

    Thanks in advance for your help!
     
    Last edited: Aug 25, 2020
  2. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    We have the same issue - I am not 100% sure about the truthiness of what I'm about to say, but I think we have only seen it on iOS-devices. It seems to be related to OnCollision/Grounded , that is, our character is jumping, falls through the ground and into our "revive the player if he falls through the ground"-trigger and then will just fall through the ground repeatedly when trying to respawn, because our ground collider somehow has stopped working.

    From the other threads - this one does seem like the most esoteric, but also most promising
    https://forum.unity.com/threads/cha...collider-but-very-rarely.436841/#post-6260809

    TLDR paraphrasing: "a position elsewhere in the game would pass float.MaxValue. This caused some math operations in the code to throw errors, and somehow affect the call stack down to the character controller. "
     
  3. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    190
    I forgot to update here, but I've been following on this here:
    https://forum.unity.com/threads/colliders-randomly-stops-working.405948/page-3#post-6976112

    And we had finally managed to reproduce the issue and confirm the fix, so this bug should now be fully fixed from 2021.1.5f1.

    If you think you have the same bug, I recommend you upgrade to latest and see if it still happens. Now the bug we had and that is solved was very rare and in builds only. If it happens a lot or does happen in editor, 90% chance it's a different Unity bug, or a bug in your game's jump/gravity code side or colliders ;)

    Hope this helps,
    Charles
     
    GuardHei and havchr like this.
  4. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    Thanks - this is great. It is definitely the same bug, exact same modus operandi.