[Bug] Immediate Unequip and Reequip Slots cause error in Balance

Cheo

Active member
Hello, I'm posting this here since I spotted this issue while experimenting with the Balance ability but haven't tried with others DetectGroundAbilityBase abilities. In the Agility Demo scene, when selecting the player character's Balance ability and setting Slot 0 and 1 to false and Immediate Unequip and Reequip Slots to true, the following error may be thrown when reaching the other side of the bridge :

C#:
[Exception] NullReferenceException: Object reference not set to an instance of an object
Balance.UpdateRotation() at /Opsive/UltimateCharacterController/Add-Ons/Agility/Scripts/Balance.cs:79
  77:  {
  78:      // The character should orient towards the direction of the balance object.
-->  79:      var targetRotation = Quaternion.Slerp(m_Rigidbody.rotation,
  80:                          Quaternion.LookRotation(m_GroundTransform.forward * (Vector3.Dot(m_GroundTransform.forward, m_Rigidbody.rotation * Vector3.forward) < 0 ? -1 : 1), m_CharacterLocomotion.Up),
  81:                          m_ForceDirectionInfluence);

UltimateCharacterLocomotion.UpdateRotation() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:687
 686:  for (int i = 0; i < m_ActiveAbilityCount; ++i) {
--> 687:      m_ActiveAbilities[i].UpdateRotation();
 688:  }
 689:  for (int i = 0; i < m_ActiveItemAbilityCount; ++i) {

CharacterLocomotion.UpdateCharacter() at /Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:576
 575:  // Update the rotation before the position so the forces will be applied in the correct direction.
--> 576:  UpdateRotation();
 578:  // Set the new rotation.

UltimateCharacterLocomotion.UpdateCharacter() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:591
 589:  }
--> 591:  base.UpdateCharacter();
 593:  // Update the animations.

CharacterLocomotion.Move() at /Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:562
 560:  EnableColliderCollisionLayer(false);
--> 562:  UpdateCharacter();
 564:  EnableColliderCollisionLayer(true);

SimulationManager+SmoothedCharacter.Move() at /Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:169
 167:      }
--> 169:      m_Locomotion.Move(horizontalMovement, forwardMovement, deltaYaw);
 170:      AssignFixedLocation();
 171:  }

SimulationManager.MoveCharacters() at /Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:723
 721:  for (int i = 0; i < m_Characters.Count; ++i) {
 722:      if (interpAmount == -1) {
--> 723:          m_Characters[i].Move(preMove);
 724:      } else {
 725:          if (!m_Characters[i].Locomotion.Interpolate) {

SimulationManager.FixedUpdate() at /Opsive/UltimateCharacterController/Scripts/Game/SimulationManager.cs:671
 669:  MoveCharacters(true, -1);
 670:  RotateCameras();
--> 671:  MoveCharacters(false, -1);
 672:  MoveCameras(-1);

If I am not mistaken, what's null is m_GroundTransform.

I also got another error when starting the ability but haven't been able to reproduce it yet. Anyway I hope this can be taken a look at, as it is currently impossible to have an Uncharted-like ability with the character unequipping and requipping his current item when the ability starts and stops. Thanks in advance.
 
You're correct, it is related to a ground transform not being found. You can fix this by adding a simple null check at the start of Balance.UpdateRotation:
Code:
if (m_GroundTransform == null) { 
   return;
}
 
Top