Bug: Cant shoot after exception thrown attempting to access detroyed mesh renderer

wrongdog

New member
Products: 1st and 3rd Person Character controller
Unity: 2019.3.10f1 with Universal RP version 7.3.1 (marked 2019.3 certified)

Description: Using hitscan to shoot 'enemies' and randomly throws exceptions that immediately to character lockups where i can not shoot, unequip or change weapons, though locomotion and aiming still work fine. Death and respawn does not correct the issue, the game has to be restarted.

Steps to reproduce: Create a number of 3d object and put a hit detector script that implements OnImpact that will count down the objects 'health' and then destroy the object once health reaches zero. After killing a random number of objects (sometimes 1, sometimes 10) the error happens and the game has to be restarted.

It looks like this is a decal issue, where you are trying to remove decals from an object that I just destroyed. I can work around the issue by calling SetEnabled(false) instead of immediately destroying the object, but this leaves them hanging around in memory and will need to be reaped out of memory later.

Error Message:


MissingReferenceException: The object of type 'MeshRenderer' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Renderer.get_material () (at /home/builduser/buildslave/unity/build/Runtime/Export/Graphics/GraphicsRenderers.bindings.cs:133)
Opsive.UltimateCharacterController.SurfaceSystem.DecalManager.WeatherDecals () (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/DecalManager.cs:253)
Opsive.UltimateCharacterController.SurfaceSystem.DecalManager.Add (UnityEngine.GameObject decal) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/DecalManager.cs:242)
Opsive.UltimateCharacterController.SurfaceSystem.DecalManager.SpawnDecal (UnityEngine.GameObject original, UnityEngine.RaycastHit hit, UnityEngine.Quaternion rotation, System.Single scale, System.Single allowedEdgeOverlap) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/DecalManager.cs:162)
Opsive.UltimateCharacterController.SurfaceSystem.DecalManager.SpawnInternal (UnityEngine.GameObject original, UnityEngine.RaycastHit hit, System.Single scale, System.Single allowedEdgeOverlap) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/DecalManager.cs:87)
Opsive.UltimateCharacterController.SurfaceSystem.DecalManager.Spawn (UnityEngine.GameObject original, UnityEngine.RaycastHit hit, System.Single scale, System.Single allowedEdgeOverlap) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/DecalManager.cs:75)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceEffect.SpawnDecal (UnityEngine.RaycastHit hit) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceEffect.cs:118)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceEffect.Spawn (UnityEngine.RaycastHit hit, UnityEngine.Vector3 gravityDirection, System.Single timeScale, UnityEngine.GameObject originator, System.Boolean spawnDecals) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceEffect.cs:90)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager.SpawnEffectInternal (UnityEngine.RaycastHit hit, UnityEngine.Collider collider, Opsive.UltimateCharacterController.SurfaceSystem.SurfaceImpact surfaceImpact, UnityEngine.Vector3 gravityDirection, System.Single timeScale, UnityEngine.GameObject originator) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:203)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager.SpawnEffect (UnityEngine.RaycastHit hit, Opsive.UltimateCharacterController.SurfaceSystem.SurfaceImpact surfaceImpact, UnityEngine.Vector3 gravityDirection, System.Single timeScale, UnityEngine.GameObject originator) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:166)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.HitscanFire (System.Single strength) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:971)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.Fire (System.Single strength) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:737)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.UseItem () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:655)
Opsive.UltimateCharacterController.Character.Abilities.Items.Use.LateUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/Use.cs:632)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateActiveAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities, System.Int32& abilityCount) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1029)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1015)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdatePositionAndRotation () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:826)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.UpdatePositionAndRotation (System.Boolean fromAnimatorMove) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:517)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.OnAnimatorMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:1471)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.OnAnimatorMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1757)
 
Thanks - you should be able to fix this by adding the following within the DecalManager.WeatherDecals loop:

Code:
                if (m_WeatheredDecals[i] == null) {
                    m_WeatheredDecals.RemoveAt(i);
                    continue;
                }
 
Top