Action Buttons are not clickable

I’m also having an issue where the action buttons are not clickable. The UI is correctly rendering either one or two buttons depending on the unit that was selected. I can select units back and forth infinite number of times and it correctly re-renders with either Move or Spin. The button doesn’t show any sort of click animation like I see in the videos and the listener never fires.

public class ActionButtonUI : MonoBehaviour
    [SerializeField] private TextMeshProUGUI textMeshPro;
    [SerializeField] private Button button;

    public void SetBaseAction(BaseAction baseAction)
        textMeshPro.text = baseAction.GetActionName().ToUpper();
        //this code gets executed
        button.onClick.AddListener(() => { 
            //this code never gets executed

I figured out my issue. But I don’t know why exactly my fix works though. Perhaps someone can explain.

A few lectures ago I noticed a game object in my hierarchy got created called “Event System” Curious what it was, I disabled it (but didn’t delete it). Nothing wrong seemed to happen for lecture after lecture. I was thinking of deleting it. Well until it struck me just moments ago to go and enable it. The clicking started working. But I have no idea how this object got created, when it got created, and why disabling it only seems to affect button clicks.

Ok I think I figured out my issue more thoroughly. In an earlier lesson perhaps when we were creating the GridDebugObject I think I created the wrong kind of Text object initially (the kind that needed a canvas). I quickly caught my error, deleted that object and created it the right way. But creating anything with a Canvas seems to create an EventSystem object. It went unnoticed initially and then when I caught it I decided to disable it (I probably would have been better off deleting it now that I think about it). Having it disabled had no consequence until this lesson (I literally spent over an hour debugging).

For whatever reason (and after I posted this question) I decided to try enabling the Event System and everything started working.

I think that answers everything. Wow. What a nasty bug if you don’t know what EventSystem objects are.

The EventSystem is required for any UI that’s added to the scene. This is the object that handles UI events like clicks on buttons, etc. If you have UI, you have to have an EventSystem object. This is why it gets added automagically when you add the first UI object

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms