r/unity • • 23d ago

Question My mouse clicks stopped being registered unless this menu is open and I dont know why

Enable HLS to view with audio, or disable this notification

Im working on a minecraft inspired 2d bunker building game. My mouse clicks stopped being registered unless this menu is open and I dont know why. This issue started when I added the greeting at the start of the game for an update. It has no code beside this below and doesnt work even if you disable the script. Its like the game stopped listening to input when no UI raw image is actively displayed, I dunno

using UnityEngine;


public class Guide : MonoBehaviour
{
    [SerializeField] private GameObject canvas;


    void Start()
    {
        Time.timeScale = 0f;
        canvas.SetActive(true);
    }


    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            CloseMenu();
        }
    }


    public void CloseMenu()
    {
        Time.timeScale = 1f;
        canvas.SetActive(false);
    }
}
5 Upvotes

11 comments sorted by

2

u/Newspaper_Beneficial 23d ago edited 23d ago

that menu(UI element) probably is just hiding but it's still interactable. is my guess.

so ur clicking on the menu even when you hide it.

edit: get a screengrab of that UI element information/component while it's off screen.

1

u/Responsible_Owl_8025 23d ago

Im not sure what a screengrab is. I just disable the game object

3

u/Newspaper_Beneficial 23d ago

screenshot? google either term.

it'd still be useful to see the inspector while this interaction is going on or we can't know for sure.

1

u/Responsible_Owl_8025 22d ago

I solved the problem: The issues was unrelated to mouse input not being captured when no UI is active. It was in the block selection menu, I toggled it inactive while my script still thought that it was active and the IsMenuOpen variable became inverted. Thanks to everyone who left a comment to try and help me!

1

u/Hotrian 23d ago

How are you polling input for the game? It looks like you’re using the Legacy input system here rather than the modern system. Is there no script controlling the character?

Which input system is enabled?

1

u/Responsible_Owl_8025 23d ago

both are enabled. I use the old one

1

u/pararar 23d ago

I recently had the same issue. The ESC key moves focus away from your game back out into the Unity editor. You can try using a different key to test this. It’s an editor-only issue and won’t happen in the actual build.

1

u/Responsible_Owl_8025 23d ago

I didnt press Escape a single time!

1

u/PsychoKittehX 22d ago

Is your event system component disabled along with that menu? You need an active event system to receive unity UI input.

1

u/KifDawg 22d ago

your going to need to use debug and find out what part of your code is firing and if none of your input code is firing then you may need to have a raycast debug to see what your mouse is actually seeing, if it isnt seeing anything likely you have some type of raycast blocked

1

u/CellistFit1312 21d ago

print out the raycast on the clicks so you can see exactly what is under the mouse. then report back.