Buttons not responding

Bit of an odd one, I am not getting any response at all out of my buttons. I have added debug statements to check if the method is getting called and it is not.

I have an event system (as i saw this was an issue some others were having) I am also using the old input system. I am using Unity 2022.1.3f1

Some images:


code snippet for SceneLoader.cs

public void ReloadGame()

{
Debug.Log(“Clicked button”);
SceneManager.LoadScene(0);
}

SceneLoader script is attached to the Game Session object

Would appreciate any ideas!

Thanks,
Simon

What is in GameSession? It’s sitting on top of the buttons so may be blocking the raycast from the mouse

This is my game session. Just some other info that might be useful, when I click on the button I am still getting the ray hitting the terrain in the background, so the game continues like the button isn’t there.

Looks like something is blocking the click. If you click the EventSystem in the hierarchy in play mode, you will see a little window in the inspector (it may be minimised at the bottom) that shows a lot of info
image
It’s a stupid little window because there are usually more information than what can fit in it, but you may be able too see what the mouse is hovering over when you are over a button

This will happen if you use things like Camera.main.ScreenPointToWorldPosition() or even just a raycast to something in the world because it doesn’t care that there’s UI. You can prevent this by checking something like EventSystem.current.IsPointerOverGameObject() which will return true if the mouse is over UI.

This is the output of the window you mention. The only thing that happens when I click anywhere on the screen is the highlighted changes from false → true then back again as soon as my mouse button is lifted.

So I continued onto the next lesson where we don’t constrain the cursor and set it to visible, and everything works fine. Happy to chalk this up to “Unity being weird” or some odd interaction like my full screen editor not liking the buttons without cursor control.

Many thanks for your help.

2 Likes

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

Privacy & Terms