I believe I understand buttons well, and re-watched the Button UI tutorial just to be sure… In the tutorial, he says you can delete the text component if you don’t want text. I’ve removed the text component using two ways with the same result:
Using “Remove Component”
By highlighting the text child in the Hierarchy and hitting Delete key
Regardless of the removal method ,the result is that the button no longer takes mouse input. Only buttons WITH the Text child component accept mouse clicks. Seems very strange. I make NO other changes to the button.
So what am I trying to do? I just don’t need text on my buttons. I can get away with just leaving the text label blank, but I am like to “clean up” unecessary assets in my projects.
I agree with @Kiwasi . I’ve used buttons without text many times; they work fine. I’d like to see a screen shot of one of these non-working buttons, where you’ve deleted the text’s GameObject entirely (method 2), and with the button inspector visible.
There are some reasons why a button could not work. Besides the no-Image attached on the button, I can think of the following possibilities:
The button component is not enabled. The checkmark is activated at the left of the “Button (Script)” title.
The Button component has “Interactable” unchecked. This value needs to be checked for the button to work.
The Button component has no “OnClick” events. It needs something to call.
There is no “EventSystem” on the scene. This is a component to detect UI Inputs. It must be on the scene. If there is none, you can create one clicking (on the Hierarchy tab) on “Create → UI → Canvas”
The button is not inside the canvas. Every UI element needs to be inside a Canvas (on the hierarchy)
Going through the list, I have everything as you say except #3. I have no OnClick event defined. But with the Text component, the button still captures clicks and shows a “down” state (it goes dark tinted when clicked). Without the text gameobject, there is no downstate, and the button allows clicks to go through it to underlying buttons (doesn’t capture clicks). In both cases, no OnClick is defined. This is what I find strange. I should be able to preview/test the button states with or without the text gameobject, no?
I sense some skepticism, but here you go. Let me know if you notice anything.
Boom! You got it. My eyes just did not see the Raycast option up in the image options. That fixes the problem! Text has its own raycast setting turned on by default, so thats why it worked. Very strange though, no? I would think that it makes more sense to have an image capture clicks than the text.
I encounter the same problem but my raycast is on, I tried things up and figure it out, I found that button needs an image component on its own gameobject or text as its child as sort of hitbox. I was setting up my button as such the graphic would be at its parent gameobject and it doesn’t work but as soon as I add text as a child or image component to the button the input register at the position and the size of either of them regardless of the graphic setting