Trying to implement a dummy usableitem

discofever

New member
I'm trying to get a glimpse of how this 'Ultimate Black Box' works.

I've created the following dummy script for usableitem.

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using Opsive.UltimateCharacterController.Utility;
using Opsive.UltimateCharacterController.Items.Actions;

public class DummyUsableItem : UsableItem {

    protected UltimateCharacterLocomotion m_CharacterLocomotion;
    private Transform m_CharacterTransform;

    protected override void Awake()
    {
        base.Awake();

        m_CharacterLocomotion = m_Character.GetCachedComponent<UltimateCharacterLocomotion>();
        m_CharacterTransform = m_CharacterLocomotion.transform;
    }

    public override void StartItemUse()
    {
        base.StartItemUse();
        Debug.Log("StartItemUse");
    }

    public override void UseItem()
    {
        Debug.Log("UseItem");
        base.UseItem();
    }

    public override bool CanUseItem(ItemAbility itemAbility, UseAbilityState abilityState)
    {
        return true;
    }

    protected override void Start()
    {
        base.Start();
        Debug.Log("START");
    }
}

But when i use the item

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Items.AnimatorAudioStates.AnimatorAudioStateSet.StartStopStateSelection (Boolean start) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/AnimatorAudioOutput/AnimatorAudioStateSet.cs:156)
Opsive.UltimateCharacterController.Items.Actions.UsableItem.StopItemUse () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/UsableItem.cs:291)
Opsive.UltimateCharacterController.Character.Abilities.Items.Use.CanStartAbility () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/Use.cs:240)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.TryStartAbility (Opsive.UltimateCharacterController.Character.Abilities.Items.ItemAbility itemAbility, Boolean ignoreCanStartCheck) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1149)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.TryStartAbility (Opsive.UltimateCharacterController.Character.Abilities.Ability ability, Boolean ignorePriority, Boolean ignoreCanStartCheck) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1007)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.TryStartAbility (Opsive.UltimateCharacterController.Character.Abilities.Ability ability, Boolean ignorePriority) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:993)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.TryStartAbility (Opsive.UltimateCharacterController.Character.Abilities.Ability ability) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:982)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler.TryStartAbility (Opsive.UltimateCharacterController.Character.Abilities.Ability ability) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:231)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler.UpdateAbilityInput (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:128)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler.UpdateAbilityInput () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:99)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler.Update () (at Assets/Opsive/UltimateChara




Item


1552574849651.png

Dummy Script
1552574886576.png
 

Justin

Administrator
Staff member
It looks like that exception is coming from the m_UseAnimatorAudioStateSet. You'll need to create a custom inspector to go along with your new usable item in order to properly show the Use Animator Audio State Set so the editor can select a selector for it. As the bare minimum if you inherit the UsableItemInspector with your custom inspector then that should be enough (I think..).
 

discofever

New member
Well ... ended up 'commenting' that line ...
Now my other issue is that the 'Item use' ability always stays 'active' and doesn't go 'Inactive' when i release the button ... like the Aim Ability.
 

Justin

Administrator
Staff member
Commenting out that line is going to cause problems as without a use selector you'll never get the use animations or events. This could also be why your ability never ends correctly.

I also changed the custom editor attribute for the UsableItemInspector to [CustomEditor(typeof(UsableItem), true)] so you shouldn't need to create a custom editor without any implementation logic in order to show the subclass editor.
 
I also changed the custom editor attribute for the UsableItemInspector to [CustomEditor(typeof(UsableItem), true)] so you shouldn't need to create a custom editor without any implementation logic in order to show the subclass editor.
Did you update this? Or in the next update? Because I have the exact same problem.
 

discofever

New member
Adding this to the UsableItemInspector.cs fires up another error :

Code:
Instance of UsableItemInspector couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.
 

Justin

Administrator
Staff member
Did you update this? Or in the next update? Because I have the exact same problem.
You are creating a new usable item? Or getting the same error? The code above will only help if you are creating a new usable item.

Adding this to the UsableItemInspector.cs fires up another error :

Code:
Instance of UsableItemInspector couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.
That error is really strange because UsableItems aren't ScriptableObjects nor do inspectors need to derive from ScriptableObject. I just tried something similar and got the same error.

When I created a custom inspector though it did draw correctly:

Code:
    /// <summary>
    /// Shows a custom inspector for the ThrowableItem component.
    /// </summary>
    [CustomEditor(typeof(DummyUsableItem))]
    public class DummyUsableItemInspector : UsableItemInspector
    {
        /// <summary>
        /// Returns the actions to draw before the State list is drawn.
        /// </summary>
        /// <returns>The actions to draw before the State list is drawn.</returns>
        protected override Action GetDrawCallback()
        {
            var baseCallback = base.GetDrawCallback();
           
            return baseCallback;
        }

        /// <summary>
        /// Callback which allows subclasses to draw any usable properties.
        /// </summary>
        protected virtual void DrawUsableProperties() { }
    }
 

discofever

New member
But why do I need to create an Inspector for my UsableItem I don't get it and why is this error there in the first place.
Why I can't just have a usable item that does nothing and implement myself what I want ?

What now ?

Can you please kindly give us an example of a UsableItem that shows a Debug.Log("Hello World"), please ?


PS: I edited UsableItemInspector.cs which is one of your files as you suggested.
 

Justin

Administrator
Staff member
You need to create an inspector so the selector data can be serialized. After you add that inspector you don't need to make any more changes - when I used the DummyUsableItem I received the following output:

START
StartItemUse
UseItem
 
Top