Forum rules - please read before posting.

Closing menu by clicking outside it

edited January 2022 in Technical Q&A

Hello all,

I have a small Unity UI menu that I want to open when I click a hotspot. I then want the menu to close when I click outside of it. I can achieve both of these easily by setting the menu as locked off, set to appear during gameplay, and using a hotspot interaction to unlock and show the menu.
I use a large invisible button around the outside of the small menu so when you click on the main scene the small menu closes.

The problem is the character then walks to where you clicked when closing the menu.

I also tried using Actionlists to constrain the player- which works, but the method I'm using to close the menu (gameobject.setactive to false on the onclick() event of the surrounding button) doesn't seem to call the closing actionlist to unconstrain the player. Constraining movement seems like the best option for me as I would like my shaders and environmental scripts to keep running in the main scene.

Am I overcomplicating this?

Comments

  • Figured I would post an update and my solution.

    A Hotspot and Interaction are used to open the menu by calling a custom Action under the menu category. I also call an ActionList to disable movement for the character.

    The invisible button that spans the entire view behind my small menu is used to close that canvas. That button click calls an ActionList to enable movement on the character.

    No idea if this is an appropriate solution since I am relatively new to Unity UI and AC but I figured I'd share it since my searches and keywords weren't yielding the results I was looking for before.

  • To close the menu, you'll want to rely on AC's Menu: Change state Action, or the Turn Off Menu Button command, rather than disabling it manually.

    If you link the Button up to the Menu as a Button element, that should prevent clicks underneath from being recognised.

    Alternatively, the Settings Manager's Unity UI blocks interaction and movement? option can be checked to prevent clicks on UI components not linked to AC from also being recognised on the scene underneath.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.