CharacterLocomotion.EnableColliderCollisionLayer NullreferenceException.

Kehaw

Member
Hello:

1. Character controller variant (Ultimate Character Controller, UFPS, etc).
Ultimate Character Controller

2. Unity version (include which SRP, beta Unity versions aren't supported)
Unity 2022.3.50f1 URP

3. Bug description
Shoot NPC, before NPC die, console print stack error, game stuck. But not every time, just sometimes.

4. Steps to reproduce from a fresh project

- Install UCC, UIS, Behavior Designer, A* Pathfinding, FoW (fog of war).
- Add Hider to NPC, when NPC is outside the view distance, NPC hide all renderers, this feature powered by FoW.
- Shoot NPC when NPC in the view distance (displayed).

5. The full error message (if any)

Full stack errors here (print many times):

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Character.CharacterLocomotion.EnableColliderCollisionLayer (System.Boolean enable) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:1771)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.Move (System.Single horizontalMovement, System.Single forwardMovement, System.Single deltaYawRotation) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:566)
Opsive.UltimateCharacterController.SimulationManager+SmoothedCharacter.Move (System.Boolean preMove) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:169)
Opsive.UltimateCharacterController.SimulationManager.MoveCharacters (System.Boolean preMove, System.Single interpAmount) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:739)
Opsive.UltimateCharacterController.SimulationManager.FixedMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:679)
Opsive.UltimateCharacterController.SimulationManager.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:668)
 
Last edited:
I do not have the Fog of War asset so am not able to reproduce it. Can you tell me how to reproduce it without Fog of War? I just disabled all renderers on the character and it didn't throw any errors. What else does the asset do?

Also, line 1771 of CharacterLocomotion.cs is a newline for me. What object is null?
 
Code:
/// <summary>
/// If the collision layer is disabled then all of the character's colliders will be set to an IgnoreRaycast layer. This
/// prevents any CapsuleCast or SphereCasts from returning a collider added to the character itself.
/// </summary>
/// <param name="enable">Should the layers be enabled?</param>
public void EnableColliderCollisionLayer(bool enable)
{
    // Protect against duplicate enabled values changing the collider layer.
    if (m_CollisionLayerEnabled == enable) {
        return;
    }
    m_CollisionLayerEnabled = enable;

    if (enable) {
        for (int i = 0; i < m_ColliderCount; ++i) {
            m_ColliderGameObjects[i].layer = m_ColliderLayers[i];
        }
        for (int i = 0; i < m_IgnoredColliderCount; ++i) {
            m_IgnoredColliderGameObjects[i].layer = m_IgnoredColliderLayers[i];
        }
    } else {
        for (int i = 0; i < m_ColliderCount; ++i) {
            m_ColliderLayers[i] = m_ColliderGameObjects[i].layer;
            m_ColliderGameObjects[i].layer = LayerManager.IgnoreRaycast;
        }
        for (int i = 0; i < m_IgnoredColliderCount; ++i) {
            if (m_IgnoredColliderGameObjects[i] is null) {
                Debug.Log(i);
            }
            m_IgnoredColliderLayers[i] = m_IgnoredColliderGameObjects[i].layer;
            m_IgnoredColliderGameObjects[i].layer = LayerManager.IgnoreRaycast;
        }
    }
}

I disabled all components about FoW but problem still exists, so it is not FoW's problem.

I debug whole last night, and found

Code:
//m_IgnoredColliderGameObjects[i] is null i=11

If print all items in m_IgnoredColliderGameObjects at the beginning, the item with index 11 is `Bullet Trail`, it is a projectile of gun.

So, I thing it is maybe triged by Projectile, but I still no idea why projectile can throw an Exception in CharacterLocomotion.cs

Please help me if you have any idea about this problem.
 
The projectile of a gun shouldn't be included in that list. How are you spawning that projectile? Can you completely remove that projectile and see if you no longer get the collision error?
 
The projectile of a gun shouldn't be included in that list. How are you spawning that projectile? Can you completely remove that projectile and see if you no longer get the collision error?
Could it be related to Collision->Detect Ground and the Collider Layer Mask in UltimateCharacterLocomotion? I set the Terrain layer to Ground and it seemed to solve the problem, but I'm not sure since it didn't happen before.

If this problem recurs, I will continue testing.
 
The Collider Layer Mask determines what objects go in the collision detection arrays so yes, that could have an effect. You should not have any non-character objects in this array.
 
The Collider Layer Mask determines what objects go in the collision detection arrays so yes, that could have an effect. You should not have any non-character objects in this array.
Thank you very much, I set Collision -> Collider Layer Mask only include character layer right now.
 
Back
Top