Another Equip Problem

forzabo

Member
I've got another baffling issue with equipping & unequipping an item.

The character has a default slot 0 melee weapon, which is configured to not be droppable.

Then there is a throwable grenade-type item that the character can pickup & equip -- also slot 0.

The first time the character picks it up, it can be equipped by using either "next weapon" or "previous weapon" -- but not by "toggle weapon"

The second and subsequent times the character picks it up, the exact opposite is true -- only "toggle weapon" works to equip it.

I feel like maybe this is some kind of item slot conflict, but I'm baffled as to what it could be.

As always, any hints appreciated.
 
Any chance that you can reproduce it within the demo scene? There is a lot that can happen which prevents an item from being equipped and this page lists the common troubleshooting steps (which I'm sure you've seen). If I can reproduce it then I can step through the code to see what's wrong.
 
Thanks Justin -- yeah, as you've surmised, I've stepped through the troubleshooting steps on that page multiple times. I have toggled off the wait for animation events, etc.

I'm curious what internally is the logic that differentiates "toggle item" from "next item" and "previous item" -- it seems like maybe there is a clue in there somewhere. Things get even weirder when there are more than two items: sometimes "toggle" works, sometimes "prev and next" work, but it's difficult to discern a pattern.

I kind of wish there was a simple way to force equip an item that's already in inventory; in my game the equip / unequip animations aren't important (if that's even what is the hangup)

I'll have to circle back to this as I have to work on some other aspects of the game, but I do need to get it solved...

thanks,

--Bo
 
I'm curious what internally is the logic that differentiates "toggle item" from "next item" and "previous item" -- it seems like maybe there is a clue in there somewhere. Things get even weirder when there are more than two items: sometimes "toggle" works, sometimes "prev and next" work, but it's difficult to discern a pattern.
Toggle Item keeps track of the last equipped item set from the category, whereas previous and next item will equip the a new item set.

I kind of wish there was a simple way to force equip an item that's already in inventory; in my game the equip / unequip animations aren't important (if that's even what is the hangup)
On the Equip Unequip ability there are different inputs for the start type that correspond to the keys 1-9. This calls EquipUnequip.StartEquipUnequip and is the same method that the other equip abilities use.
 
Justin -- Thank you.

I didn't really completely understand your response at first, and while all the necessary clues are in the docs and the code, It took me a while to piece this together.

For anyone else looking for a simple solution to force equip an item at any arbitrary time, here's how you do it:

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

public class Foo : MonoBehaviour
{
    [Tooltip("The character that should use force equip/unequip")]
    [SerializeField] protected GameObject m_Character;
    EquipUnequip m_EquipUnequip;

    private void Start()
    {
        //get a reference to the EquipUnequip ability instance
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        m_EquipUnequip = characterLocomotion.GetAbility<EquipUnequip>();
    }
  
    //arbitrary force equip example
    void Update()
    {
    //force item set 1 to equip after "P" keypress
      if (Input.GetKeyUp(KeyCode.P))
        {
            m_EquipUnequip.StartEquipUnequip(1, true, true);
        }
    } 
}
 
Last edited:
Top