Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved My UI buttons have the wrong hitboxes on them (consistently but not always)

Discussion in 'UI Toolkit' started by SacredSticks, May 5, 2024.

  1. SacredSticks

    SacredSticks

    Joined:
    Dec 15, 2020
    Posts:
    5
    I'm building my UI for my project using UI Toolkit but I'm building them in C# as I strongly prefer that over UXML or the editor solutions. Here's the problem, my buttons are behaving strangely and I haven't had this issue before.

    I'm working in Unity 2023.2.14f1 for context. I've created my main menu with no issues at all, it has sub menus as well, one for controls, settings, and context for player abilities. Each sub-menu has a button that redirects back to the main menu. In the main menu, these all function perfectly as expected.

    I just created a pause menu, which has buttons: Resume Game, settings, controls, and again context for player abilities. As you may assume, I'm reusing the menu's from the main menu here. The pause menu buttons work just fine, except for the last one: the quit to menu button. I assure you, I'm creating them all the same way, but that's not even related to the problem, as you're about to see.

    Like I said earlier, I'm reusing the main menu's submenus for the pause menu submenus as well. Literally 1 for 1 the same, the same prefab is used for both with no modifications in either scene. However, in the pause menu, these aren't working. The button on the submenus that closes them and reopens the previous menu isn't working.

    This isn't an issue with the C# programming for the buttons functions. I have a Buttton:hover and I can see that it isn't registering the mouse hovering over the buttons except in very specific positions around the top or bottom border of the buttons. I mentioned in the title "consistently but not always" and that may be confusing. It's not always because like I said, in my main menu those sub menu's work 100% of the time, but it's also consistent because the buttons that don't work correctly in the pause menu never change.

    Again, I'm using the same method to build all my menus but that's not relevant because the same menu is behaving differently in different scenes. If anybody has any advice on how I can fix this, I would greatly appreciate it. Thanks!
     
  2. SacredSticks

    SacredSticks

    Joined:
    Dec 15, 2020
    Posts:
    5
    Solved it myself after a few hours break and thinking about it. Turns out that the UI was being covered by another UI I had made. I just didn't notice that because the other one was empty (it's an inventory and only shows up when there are items in it, but it always exists, so it was still blocking the buttons).

    Long story short, in case someone else is having this issue I just adjusted the Sort Order of my document to put the buttons on top of the HUD documents.
     
    SimonDufour likes this.