Item Equip/Unequip Event Trigger

maherar

Member
In UCC when we equip/unequip any item, events are executed with strings "OnAnimatorItemEquip" and "OnAnimatorItemunequip".
I want to apply the wait functionality till the event with this string is triggered.

Please note... I want to apply something like this...

C#:
m_UseEvent.WaitForEvent(ExecuteEvent, "OnAnimatorItemEquip"); // Something similar
Then do{
    Print ("After wait, next lines will run");
}

I looked into your documentation, and not sure is this what I am looking for or something else. If this is, what I am looking for, there are few variables if you would explain me. It will be grateful to you. i.e.
Type of these variables.. m_UseEvent, register, eventTarget,

I am looking forward to hearing from you.
 
There is an Animation Event Trigger:


For equip and unequip this is set on the Character Item component.
 
I know where there are triggering... I want to get event trigger with the "OnAnimatorItemEquip" string in my script,
How I can achieve that?

I am trying this way...

C#:
private void Start()
    {
        EventHandler.RegisterEvent<string>(gameObject, "OnAnimatorItemEquip", OnWaveStart);
    }

    private void tested()
    {
        EventHandler.ExecuteEvent(gameObject, "OnAnimatorItemEquip");   //Here is the Error
    }
    public  void OnWaveStart(string eventName)
    {
        while (itemEquiped)
        {
            if (eventName.Contains("OnAnimatorItemEquip"))
            {
                itemEquiped = true;
                Debug.Log($"Testing {Time.frameCount} Execute {eventName} on GameObject.");
            }
            else
            {
                itemEquiped = false;
                Debug.Log($"Elseee Execute {eventName} on GameObject.");
            }
        }
    }

    public void OnDisable()
    {
        EventHandler.UnregisterEvent<string>(gameObject, "OnAnimatorItemEquip", OnWaveStart);
    }

but facing this issue...
NullReferenceException: Object reference not set to an instance of an object
Opsive.Shared.Events.EventHandler.ExecuteEvent (System.Object obj, System.String eventName) (at <6ee9d952a9384b4ea988fa1f7efc55d9>:0)
test2.Update () (at Assets/testScript.cs:8)
 
Last edited:
I know where there are triggering... I want to get event trigger with the "OnAnimatorItemEquip" string in my script,
How I can achieve that?

I am trying this way...

C#:
private void Start()
    {
        EventHandler.RegisterEvent<string>(gameObject, "OnAnimatorItemEquip", OnWaveStart);
    }

    private void tested()
    {
        EventHandler.ExecuteEvent(gameObject, "OnAnimatorItemEquip");   //Here is the Error
    }
    public  void OnWaveStart(string eventName)
    {
        while (itemEquiped)
        {
            if (eventName.Contains("OnAnimatorItemEquip"))
            {
                itemEquiped = true;
                Debug.Log($"Testing {Time.frameCount} Execute {eventName} on GameObject.");
            }
            else
            {
                itemEquiped = false;
                Debug.Log($"Elseee Execute {eventName} on GameObject.");
            }
        }
    }

    public void OnDisable()
    {
        EventHandler.UnregisterEvent<string>(gameObject, "OnAnimatorItemEquip", OnWaveStart);
    }

but facing this issue...

I'm not completely following what you are trying to do. You are getting an error within Update but you didn't paste the update method. OnAnimatorItemEquip is called by the item class so you should not call it manually. If you want to execute an event you should name it something else.
 
Last edited:
I'm not completely following what you are trying to do. You are getting an error within Update but you didn't paste the update method. OnAnimatorItemEquip is called by the item class so you should not call it manually. If you want to execute an event you should name it something else.
Oh, forget to update all. tested() this function was an update function. I want to convert a bool variable into true when "OnAnimatorItemEquip" this event triggers in my script. . that's what I am trying for the last couple of days.
 
I want to convert a bool variable into true in my script when the "OnAnimatorItemEquip" event triggers. that's what I have been trying for the last couple of days. Please guide me on how I can achieve that. Thanks
 
You should not execute OnAnimatorItemEquip as that event is called by the animator. If you want to listen for an event when the item is equipped you should listen for the OnInventoryEquipItem. The events page in the documentation contains what parameters this event uses or you can search the code base for examples.
 
Top