Bug with Custom Abilities in Latest Version?

wInevitable

New member
Having trouble adding custom abilities after updating to the latest UCC version.

I have a custom ability "NoMovement" that freezes the Player position. It is quite simple and based off of the video here https://opsive.com/support/document...r-controller/character/abilities/new-ability/.

C#:
using Opsive.UltimateCharacterController.Character.Abilities;

public class NoMovement : Ability {}

I have also added the sub-state/etc to the Player Animator. This ability used to work just fine. Now, it will randomly disappear from the list of abilities in the Ultimate Character Locomotion script. This happens in 2 different ways:

1. Re-ordering abilities in the Editor. I add the custom ability to the list and try to drag it higher in the order. The ability is completely dropped from the Character. Disappears into thin air.
2. When I am able to successful re-position the custom ability in the UCL ability list, the ability will sometimes disappear when loading the scene. Note: I am usually able to play the scene just fine, but if I navigate between scenes, the ability will disappear and break the scene when loading the scene that uses the custom ability.

In the first case, I get this error which seems unrelated to the Ability itself, but rather caused by the fact that the custom ability is no longer present in the abilities list:

C#:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Editor.Inspectors.Character.UltimateCharacterLocomotionInspector.OnAbilityListReorder (UnityEditorInternal.ReorderableList list) (at Assets/Opsive/UltimateCharacterController/Editor/Inspectors/Character/UltimateCharacterLocomotionInspector.cs:610)
UnityEditorInternal.ReorderableList.DoDraggingAndSelection (UnityEngine.Rect listRect) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:767)
UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:593)
UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:412)
Opsive.UltimateCharacterController.Editor.Inspectors.Utility.ReorderableListSerializationHelper.DrawReorderableList (UnityEditorInternal.ReorderableList& reorderableList, Opsive.UltimateCharacterController.Editor.Inspectors.InspectorBase inspector, System.Array drawnObject, System.String serializedData, UnityEditorInternal.ReorderableList+HeaderCallbackDelegate drawHeaderCallback, UnityEditorInternal.ReorderableList+ElementCallbackDelegate drawElementCallback, UnityEditorInternal.ReorderableList+ReorderCallbackDelegate reorderCallback, UnityEditorInternal.ReorderableList+AddCallbackDelegate addCallback, UnityEditorInternal.ReorderableList+RemoveCallbackDelegate removeCallback, UnityEditorInternal.ReorderableList+SelectCallbackDelegate selectCallback, System.Action`1[T] drawSelectedElementCallback, System.String key, System.Boolean requireOne, System.Boolean indentList) (at Assets/Opsive/UltimateCharacterController/Editor/Inspectors/Utility/ReorderableListSerializationHelper.cs:75)
Opsive.UltimateCharacterController.Editor.Inspectors.Character.UltimateCharacterLocomotionInspector.<GetDrawCallback>b__32_0 () (at Assets/Opsive/UltimateCharacterController/Editor/Inspectors/Character/UltimateCharacterLocomotionInspector.cs:291)
Opsive.UltimateCharacterController.Editor.Inspectors.StateSystem.StateBehaviorInspector.OnInspectorGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Inspectors/StateSystem/StateBehaviorInspector.cs:92)
UnityEditor.InspectorWindow.DoOnInspectorGUI (System.Boolean rebuildOptimizedGUIBlock, UnityEditor.Editor editor, System.Boolean wasVisible, UnityEngine.Rect& contentRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1625)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

In the latter case, I get the following error and when I exit Play mode, the ability is no longer in the abilities list in the UCL script.

C#:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.Awake () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:302)

I am able to replicate #1 in the Demo Scene, but haven't setup cross-scene loading with Demo to test #2.
 
Custom abilities are not treated any differently than the built in abilities so this is likely more of a general problem. Can you follow this post for both of those errors so I can reproduce it?
 
FWIW I'm seeing the exact same behavior. First time I load a scene with UCC prefab w/ custom ability, everything works great. If I switch to a different scene (back to main menu) and then back into the UCC scene, my custom ability goes missing, the locomotion component is disabled, and I get the following errors:

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.Awake () (at Assets/Third Party Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:302)



Code:
IndexOutOfRangeException: Index was outside the bounds of the array.
Opsive.UltimateCharacterController.Game.KinematicObjectManager.SetCharacterMovementInputInternal (System.Int32 characterIndex, System.Single horizontalMovement, System.Single forwardMovement) (at Assets/Third Party Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:546)
Opsive.UltimateCharacterController.Game.KinematicObjectManager.SetCharacterMovementInput (System.Int32 characterIndex, System.Single horizontalMovement, System.Single forwardMovement) (at Assets/Third Party Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:535)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler.Update () (at Assets/Third Party Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:71)

As far as I can tell, the first error is due to an ability that stopped existing and the array length wasn't updated, so it tries to call Awake() on an ability that has disappeared.

For the second error, this appears to be due to the fact that on the second load the locomotion component is disabled, although I'm not sure if that's something in my game logic causing that, or if it's disabled after the UCL Awake() function fails.
 
When you hit the first error I wouldn't put any trust into other errors. Can you follow this post and list the steps to reproduce from a fresh project? You can also send a small repro scene to support@opsive.com.
 
Hi Justin, sure thing, I just replicated it with a fresh project and will be sending you a bug report and a screencast of the error occuring.
 
I ran into it again with AI Agents while using Behavior Designer. I haven't noticed any issues with the base abilities that come with UCC, but both Custom Abilities and abilities from the Agility add-on pack are disappearing when switching between scenes.

I added some debuggers to try and track this down. I've gotten as far as SerializeAbilities in AbilityBuilder. I can see that some of the abilities fail to serialize, but I'm not sure why yet. Logging abilities.ToArray().Length in my scene returns 14, but logging Serialization.Serialize<Ability>(abilities).Length returns 9. So 5 abilities disappeared -- I'm guessing serialization failed? In this case, 2 custom abilities, dodge, roll and vault.

Do you have any thoughts on what could be causing this and do you still need a repro scene? Also, I've tried adding abilities once the scene has started and that seems to work, but I'm not sure I'm doing it correctly. Is there a best practice for updating a model's abilities via script?

Info:

1. Ultimate Character Controller both with and without Behavior Designer and the Agility add-on.

2. Unity version 2018.3.9f1.

3. Agility add-on abilities and custom abilities appear to be failing to serialize properly and disappear from the UCL script..

4. Setup a multi-scene project. Add a custom or agility ability to a UCL character within one of the scenes. Enter the scene with the character, leave the scene, re-enter and the abilities should disappear.

5. There is an error message in my post above "Object reference not set to an instance of an object" in UltimateCharacterLocomotion.Awake(). Basically, anytime you try to reference one of the missing abilities via m_Abilities[i] you will receive an error, but I believe the root cause is because of the serialization behavior I mentioned above.
 
Last edited:
This post has the fix :)

 
Top