If you're having strange behavior clicking Action buttons

Hi!

I’ve been struggling for a while now. All was set correctly, but whenever i clicked an action button, it was like the ActionButtonUi.SetBaseAction for all buttons was clicked the onClick itself did not fire.

Then I found out you need to add this check:


        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }


to UnitActionSystem.Update. After that, all was working fine.

TBH, IDK what’s happening here, but I wanted to share this just in case someone else is also having the same problem.
I hope it helps someone. :slight_smile:

Regards,
Breno.

What this does is to check if the mouse is over a UI item and if it is, exit the Update. I have that same code in my Update.
Clicking anywhere lets the UnitActionSystem try to see if you clicked a unit. If you click a button, this is a click, and the UnitActionSystem does its thing. If the action button happens to be over a unit, it will select the unit, in addition to selecting the action. If it’s just over the grid, it may signal the unit to perform an action in addition to selecting the action. This line of code prevents this from happening because it exits the Update instead of running all its code

2 Likes

Thanks for the explanation!

It was really weird because the action buttons were not working at all. Didn’t matter if there was something behind them or not.
Then I added this check and voila! Everything works! :smiley:

Privacy & Terms