Height Change's Allow Speed Change can cause an error in Item Equip Verifier

Cheo

Active member
Alright, this one is going to sound very weird, but please bear with me ! So I was trying to replicate MGS's crawl by having the crouch ability started with a simple press of the Crouch button, and the crawl ability started by a long press. But when starting the crawl ability with my own character holding a weapon, I got an error from Item Equip Verifier - Editor Console Pro's dev finally sent me a fixed dll which allows for pasting the stack and source without color tags, so here it is :

Code:
[Exception] NullReferenceException: Object reference not set to an instance of an object
ItemEquipVerifier.ShouldStopActiveAbility() at /Opsive/UltimateCharacterController/Scripts/Character/Abilities/ItemEquipVerifier.cs:266
 264:      }
--> 266:      return m_StartingAbility.ShouldStopActiveAbility(activeAbility) || m_StartingAbility.Index < activeAbility.Index;
 267:  }

UltimateCharacterLocomotion.TryStartAbility() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:877
 875:  // The ability can start. Stop any currently active abilities that should not be started because the current ability has started.
 876:  for (int i = m_ActiveAbilityCount - 1; i >= 0; --i) {
--> 877:      if (ability.ShouldStopActiveAbility(m_ActiveAbilities[i])) {
 878:          TryStopAbility(m_ActiveAbilities[i], true);
 879:      }

Ability.StartAbility() at /Opsive/UltimateCharacterController/Scripts/Character/Abilities/Ability.cs:458
 456:  public bool StartAbility()
 457:  {
--> 458:      return m_CharacterLocomotion.TryStartAbility(this);
 459:  }

ItemEquipVerifier.TryToggleItem() at /Opsive/UltimateCharacterController/Scripts/Character/Abilities/ItemEquipVerifier.cs:193
 191:          StartEquipUnequip(false);
 192:      } else {
--> 193:          StartAbility();
 194:      }
 195:  } else if (startPossible && activate && IsActive && m_StartingAbility != null && m_StartingAbility != ability) {

UltimateCharacterLocomotion.TryStartAbility() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:907
 905:  // If TryToggleItem returns true then the ItemEquipVerifier ability has started and it will start the original ability after
 906:  // the character has finished unequipping the equipped items.
--> 907:  if (m_ItemEquipVerifierAbility.TryToggleItem(ability, true) && !ability.ImmediateStartItemVerifier) {
 908:      moveEquipStarted = true;
 909:  }

UltimateCharacterLocomotionHandler.TryStartAbility() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:226
 224:  protected virtual bool TryStartAbility(Ability ability)
 225:  {
--> 226:      return m_CharacterLocomotion.TryStartAbility(ability);
 227:  }

UltimateCharacterLocomotionHandler.UpdateAbilityInput() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:133
 131:      // they are still running (such as toggling an equipped item while waiting for the animation to do the equip).
 132:      if (abilities[i].CanInputStartAbility(m_PlayerInput)) {
--> 133:          TryStartAbility(abilities[i]);
 134:      }
 135:  }

UltimateCharacterLocomotionHandler.UpdateAbilityInput() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:100
  99:      // Update the input for both the regular abilities and item abilities.
--> 100:      UpdateAbilityInput(m_CharacterLocomotion.Abilities);
 101:      UpdateAbilityInput(m_CharacterLocomotion.ItemAbilities);
 102:  }

UltimateCharacterLocomotionHandler.Update() at /Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:75
  73:  private void Update()
  74:  {
-->  75:      UpdateAbilityInput();
  76:  }

Btw what's null is activeAbility.

Here's where it gets weird : I didn't get this error when experimenting with the character from the Agility demo scene and giving him the same ability start types, but there was one tiny difference : the Agility Atlas' Height Change ability had Allow Speed Change set to false while mine had it set to true, and when I set it to false the error no longer appeared ! But that's not all, it turns out my character also had another Speed Change ability that was disabled by default and enabled when the Crouch or Crawl states were active, and it seems that it is the activation by the Crouch state that was at the root of the issue.

Here's how you can recreate the error, it'll be clearer :
-Make a duplicate of the Agility Demo scene.
-Take the Atlas character, set its Crawl ability's Start Type to Long Press, Input Name to Crouch and its Max Trigger Count to 0. With that it should be able to start with a long press normally.
-Add a new Speed Change ability underneath the existing one. Set Enabled to false, set its Start Type to Automatic and Stop Type to Manual, create a preset setting Enabled to true, and make it activated by the Crouch state.
-Select the Height Change ability and set Allow Speed Change to true.
-Then just press play and try a long press to start the Crawl ability, and you should get the error if you followed each of these steps.

Thanks for following through all that ! You should understand that despite all of the necessary steps this is no niche case as it prevents combining an automatic speed change with the Crawl ability. I don't really understand the error at the moment but I hope this was already helpful and can be fixed. Thanks in advance.
 
I just tried that setup but am not able to reproduce the exception. Here is the scene and state that I am using.
 

Attachments

  • Repro.unitypackage
    45.9 KB · Views: 1
The second Speed Change ability needs to be activated by the Crouch state, not Crawl ! Just write Crouch instead of Crouch and I'm confident you'll get the error.
I made a mistake at the end of the post, it's the Crouch abillity that can't have a dedicated Speed Change because of this error. By the way, isn't this Allow Speed Change bool a bit superfluous ? I mean the state system is here specifically to handle this kind of thing.

Capture d’écran (1427).png
 
Hmm, even after changing it to crouch I am not getting the error.

1689066765109.png

Should the crouch HeightChange ability be activating? I haven't looked at it in depth but that ability isn't active so it makes sense that the state doesn't activate.

By the way, isn't this Allow Speed Change bool a bit superfluous ? I mean the state system is here specifically to handle this kind of thing.
Yeah, it is. It was added from version 1 of the controller and just hasn't been removed from the updates.
 
What the hell... ? It looks like I was able to start crawling without this error on first try, but then the error came back. I updated the project to Unity 2022.3.4 just before that but it shouldn't change anything. I'm gonna make another clean test project to be absolutely sure, and send a package to you if I do recreate the error. In the meantime, may I please ask you to try just 2 more times and make sure that you have the assault rifle equipped ?
 
The error happens in a clean test project in 2022.3.4 as well. A scene and a simple state preset are attached to this message for you to test.
Should the crouch HeightChange ability be activating? I haven't looked at it in depth but that ability isn't active so it makes sense that the state doesn't activate.
Yes it does activate ! You should know that, that's why I keep saying the state system is extremely convenient, apart from this specific error I often use specific Speed Change ablities that get enabled when a certain state is activated.
Edit : sorry I misread, I thought you were talking about SpeedChange x) Starting the Crawl ability deactivates the Height Change ability which naturally in turn deactivates the Crouch state which reverts the second Speed Change to disabled.

And just so we are perfectly clear : although the error is thrown when starting Crawl, it remains triggered by the Speed Change activated by the Crouch state. Can you please import the files I sent you and just try crawling by holding the crouch button while holding the assault rifle ?
 

Attachments

  • EnableSpeedChangePreset.unitypackage
    664 bytes · Views: 1
  • ItemEquipVerifierErrorTest.unitypackage
    47.9 KB · Views: 1
Last edited:
There we go. You can fix that error by adding the following to line 877 of UltimateCharacterLocomotion. The last line already exists and is for reference.

Code:
                        // The ability may be removed within the nested TryStopAbility.
                        if (m_ActiveAbilities[i] == null) {
                            continue;
                        }
                        if (ability.ShouldStopActiveAbility(m_ActiveAbilities[i])) { /// OLD
 
Top