Pause Menu Buttons Not Working (And mouse locking for no reason)

Hey! I’m currently trying to make a pause menu, and I’m making the menu the same way I made my main menu & options menu, but inside of the game scene, rather than having its own scene, since its a pause menu.

My main menu works fine, but when I pause in my pause menu, when you hover over a button, the button doesn’t highlight, when you click a button, nothing happens, and it locks your cursor in the center as if the character controller was trying to take control of the mouse. I’ve even went as far as disabling the character controller when you pause, changed nothing, so that’s not the problem…

Video of my problem:

Menu Code: https://hasteb.in/gagolida.cpp

1 Like

It can happen because the menu is probably coming in between the button. So the button might not be receiving any mouse input. Try making the menu smaller in size and showing itself on one corner only. And check again.

Wait, so what exactly should I do? Sorry, I don’t really understand… What does the menu coming between the button mean, and what do you mean but show itself on one corner only?

Oh boy, we can only really stumble in the dark here and take your word, that you’ve set up everything correctly, for granted.

Obviously if your button doesn’t work, it has to be one of the two things:

  1. you didn’t follow the protocol, and your button doesn’t receive any cues from your input
  2. you did everything right, but something else is interfering with your input, with the same result as 1

Now why does that happen? ¯_(ツ)_/¯

You need to debug, to analyze what’s going on, try some things step by step, and try and deduce what might be the underlying cause. Do some tests, give us more hints what works and what doesn’t. Try to reproduce this in another project, when you’re not using some other scripts, packages, whatnot. Debug debug debug.

What Vishwas told you is a common issue, from his experience at least, where what you’re seeing and what you’re interacting with aren’t necessarily the same things, and could be differently positioned in relation to camera. So even though you might see your button, it doesn’t mean it will behave properly. Maybe some other collider is occluding it, preventing any mouse hits.

And so on. Too many maybes.

I think the screen that says “Paused” - “Back to Game Menu” is coming in between when you try to click the button behind it. So what you are interacting with is not the button, but probably the menu. Just a guess though.

Use it
public void

hey everyone. I have had the same problem with the UI buttons on my pause menu. In my case the solution was to spend another 10 hours solving it with turning another object off which technically has nothing to do with the buttons. I suspected that (after checking all setting and code etc that I haven’t even touched since the beginning when the button were still working) something is front of the buttons hence it cant be clicked. Well…yes and no… It was the “End game fade canvas” that was blocking the stuff. I had to turn it off although when the player dies or wins the fading canvas still works… Nut sure what is going on but I suspect that maybe the event system turns it back on but otherwise when the game starts it has to be turned off???

2 Likes

I’m having the same problem, I found that (Cursor.lockState = CursorLockMode.Locked) is what have been causing that to happen, so there should be an alternative code that locks and hides cursor during the game, and interacts with buttons when the game is paused

1 Like

UPDATE
I was able to fix this problem.
If you go to your pause menu script, and in void update, you can write;

if (GameIsPaused && pauseMenuUI != null)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
} else
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}

this works if your mouse script (then void update) has;

Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;

12 Likes

I had similar problem but my pause menu worked in the first scene, but didn’t work in the second. It was strange to me why it was happening as I copied and pasted the whole canvas. I tried to create another canvas to see if it is going to work. And as I created the new canvas the EventSystem was also created. Then I dropped my canvas in EventSystem and it worked. Such small and stupid mistake. But well always something new to learn.

6 Likes

KermixOnTwitch that works!! thank you so much :slight_smile: i used something similar in my scripts

1 Like

thank you so much i had the same problem with the canvas I accidentally deleted the event system

It was the same for me, the “Fade Screen” (or whatever you named it). The fade canvas object needs to be in the Hierarchy somewhere over the “Pause Menu”.

That worked for me!!! omg thank you spend hours trying to fix it. Just had to insert into my script.

void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused && PauseMenuUI != null)
{
Resume();
}
else
{
Pause();
}
}

}

public void Resume()
{
PauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Debug.Log(“Game is not paused!!!”);
}
void Pause()
{

PauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
Debug.Log(“the game is paused!!!”);

Thanks guys!!!

1 Like

Please use code-tags when posting code. Also, please try to use the like button to show your appreciation rather than necroing posts.

Thanks.

Thank you so much bro, finally a simple answer to a simple issue. It helped me out a ton, cheers!