#UI Button not receiving AddListener on different switch cases

1 messages · Page 1 of 1 (latest)

rapid folio
#

I'm kinda losing my mind over this but for some reason when I call a function via an unity event the button sometimes isn't receiving it's AddListener. I've tried to disable every other method that calls the event so I'm sure it only gets a listener in that specific case but still nothing

    void UpdateSkillDisplay(SkillManager unitSkillManager, SkillDisplayContext reason)
    {
        Debug.Log(unitSkillManager);
        tempSkillManager = unitSkillManager;
        for (int i = 0; i < skillSlots.Length; i++)
        {
            int slotIndex = i;
            SkillData skill = tempSkillManager.GetCurrentSkill(i);

            switch (reason)
            {
                case SkillDisplayContext.SkillReplace:
                    skillSlots[slotIndex].SkillInteraction.onClick.RemoveAllListeners();

                    skillSlots[slotIndex].SkillInteraction.onClick.AddListener(DebugFunction);
                    Debug.Log($"Reason is Level Up and skill is {skill} + Slot {slotIndex}");
                    break;
                case SkillDisplayContext.Attack:
                    if (skill != null && reason == SkillDisplayContext.Attack) 
                    {
                        skillSlots[slotIndex].SkillInteraction.onClick.RemoveAllListeners();

                        skillSlots[slotIndex].SkillInteraction.onClick.AddListener(() => PlayerGameActions.onPlayerSkillUse.Invoke(slotIndex)); 
                        Debug.Log($"Reason is attack and skill is {skill}");
                    }
                    break;

                default:
                    break;
            }
            skillSlots[slotIndex].Setup(slotIndex, skill);
            Debug.Log($"Final state - Slot {slotIndex}: Interactable={skillSlots[slotIndex].SkillInteraction.interactable}");
        }
    }
#

For some reason the case of SkillReplace does work but just the AddListener doesn't

gleaming storm
#

I wonder if something else is also removing all listeners