UI Toolkit seems to be restarting the scene on Space hit

Hi All,

I’m still pretty new to Unity, so sorry if I just missed something and this is not an actual issue, but I noticed some weird behavior with UI Toolkit. So I’m implementing a game and already created a few UI-s with UI Toolkit (menus, so far). There’s also a Pause overlay menu in my game. Its container game object is not disabled, only the UI itself is hidden, so basically the overlay is always loaded, it’s just invisible. Turned out, in the built game (within editor the issue is not reproducible), when the player hits the space key, the scene kind of restarts. After some digging around I noticed that there are a few classes within UI Toolkit’s library containing “listeners” for the space key, so I turned off the overlay game object, recompiled the game, and the issue went away. Afterwards I tried if anything happens when the overlay is actually shown, and the same happened, the scene restarted on hitting the space key. What makes it even weirder, as I mentioned, the issue is not reproducible within the editor. I know I can get rid of the issue if I actually disable the game object when it’s not needed, but when the overlay is visible even an accidental space hit can restart the scene now.

Any ideas, suggestions? Did I just miss something or is it an actual issue? Thanks in advance for your help!

Some further info:

  • Unity version: 2020.3.12f1
  • UI Toolkit version: 1.0.0-preview.16
  • UI Builder version: 1.0.0-preview.17
  • Build target: Windows x86_64
  • Running on Windows 10 Pro 21H1
1 Like

Okay, so I did some further debugging and it turned out that somehow a click listener got stuck. Before the main scene there is a menu, where you need to click the New game button, which loads the main scene. Enter, and Space as its alternative are configured by default as event submit buttons. Even though the scene is changed, somehow the listener remained loaded, and hitting space (or enter, both could trigger this issue as it turned out) reloaded the scene. I managed to solve the issue by manually removing the click listener before the scene is destroyed.

1 Like

The same happened to me. Was using ‘Space’ in my game for pausing everything, only when I converted my main menu to UI toolkit, it re-triggered the “New Game” button.

So even when a new scene is loaded and the UI is not visible anymore, it can still be triggered by pressing ‘Space’