Forum rules - please read before posting.

Make UI block Clicks for movement


I have a button, that works fine when I click it, but the player also moves. I want the player to move, only when I don't click on a button. The button is a prefab of Unity UI.

I already tried with CanvasGroup's blocking object property, but it didn't work.


  • It could well be some other setting on your Canvas.  Have a look at the provided InGameUI prefab in /Assets/AdventureCreator/Demo/UI.

    That will block clicks (you can test this by assigning the Demo_MenuManager asset as your Menu Manager, viewing the InGame Menu's properties, changing the Source to Unity Ui Prefab, and changing the Click type to Run ActionList).

    Assuming the InGame UI works for you as intended, try to find the difference between that and yours that's causing the problem.
  • gbogbo
    edited March 2016
    Thanks Chris for your quick answer.

    I tried what you said, and it worked. Now the button is clicked and blocks the order of moving through the navmesh (I have it working with Unity-type navmesh). The solution was to link my prefab to the AC menu system, assigning Linked Canvas and RectTransform boundary.

    I still have a problem though. I want to have multiple buttons. But now only one of them blocks the player movement. I would guess the RectTransform boundary is responsible of blocking the clicks. Also, each object that should show a button on top of it, is controlling the position of it's button... so I can't have a static menu on the AC menu system.

    (In this image, I tried to have two buttons working, but only one of them blocked the player movement. I gave the RectTransform boundary of one of them to the AC menu controller though)
  • gbogbo
    edited March 2016
    I discovered that withought using AC, in Unity's navmesh system, it also happens that UI buttons don't block Physics.Raycast(). But in this case you can call the following:  

    if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ())
      return;  //to cancel player movement instructions below this

    Now I will try to cancell player movement in AC with this eventsystem check.
  • gbogbo
    edited March 2016
    Finally. This solved my problem:

    void Update () {

    if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ()) {
    //AC.KickStarter.player.EndPath(); // I tried this before, but you can see the player trying to move
    } else {
  • Good to hear.  AC should actually block clicks to the NavMesh if a Button "catches" it first.  This is done automatically if the Button's click event is handled by the Menu Manager, and not done manually by using Unity's Button component as normal.

    The following function can be used to reset the mouse click once it's been recieved to prevent it from having an effect on anything else AC-related:

    AC.KickStarter.playerInput.ResetClick ();
  • Hello, I've a similar problem. I could use the script gbo wrote, but I wonder why if I click a button on a UnityUI prefab that is linked to the AC Menu Manager, it still triggers the movement of my Player.
    All the rest is like gbo says... UI prefab with small buttons at the 4 corners of my screen, so I cannot set a single panel (unless it covers the whole screen, but then I cannot navigate anymore on my scene).
    So basically AC is not blocking clicks on my NavMesh even if a button is catching the click (it's a MAP button that crossfade between Menus: game goes into pause, I see the new menu, when I close the menu my player continue walking to where my MAP button is).
    Any idea why?

  • The click-blocking works by using the RectTransform boundary field for reference - so if you haven't supplied one, then clicks will not block anything.

    That is, unless you check Unity UI blocks interaction and movement? in the Settings Manager.

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.
Do NOT follow this link or you will be banned from the site!