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

[SOLVED] UI buttons only works on screen edges in editor

Discussion in 'UGUI & TextMesh Pro' started by Sinepsorg, Sep 20, 2019.

  1. Sinepsorg

    Sinepsorg

    Joined:
    May 19, 2019
    Posts:
    3
    Hi all,

    I have a problem with my buttons in the editor mode. To contextualize, I am working on a world exploring application and my buttons are in fact the text above the points of interest, so they are moving on the screen as the camera moves. But the fact is that when my buttons are on the edges of the screen, they work well. I think there is a kind of "working area" (see image bellow). Moreover, I don't encounter this issue with the executable of the app.

    upload_2019-9-20_9-35-55.png

    I have searched for solutions, and found an answer of @Hellium (https://answers.unity.com/questions/1402544/so-my-buttons-stop-working.html), which groups several solutions that I found on the Unity forum. Unfortunately, all of them didn't work for me.

    Here is my button config and its position in the hierarchy:

    Button inspector
    upload_2019-9-20_9-56-47.png

    Button hirarchy
    upload_2019-9-20_9-57-10.png

    Also, here is the configuration of my EventSystem:

    EventSystem inspector
    upload_2019-9-20_9-58-38.png

    What I want is to make it working in the Unity editor when I hit play button, even in the "not working area".
    One last thing, I am using Unity 2018.2.7f1

    Many thanks for your answers!
     
  2. Hellium

    Hellium

    Joined:
    Sep 25, 2014
    Posts:
    43
    According to your hierarchy, your Canvas is a child of several gameObjects. Is your canvas set to
    World Space
    ? If so, have you specified a camera?


    What info do you get in the
    EventSystem
    "preview window" when you hover the button?


    You haven't specified any function in the
    onClick
    event of the button. Do you add a listener by code?
     
  3. Sinepsorg

    Sinepsorg

    Joined:
    May 19, 2019
    Posts:
    3
    Hi Hellium, thank you for your reply ! :)

    My canvas is set to
    Screen Space - Overlay
    . I have tried to set it to
    World Space
    an added my camera as you said in your post, but when I do that, my button disappears (I mean, it is not destroyed or disabled, but is not visible on screen anymore).

    In my EventSystem, when I hover the button in the "Working area" I got this :

    pointerEnter: Text (UnityEngine.GameObject)

    upload_2019-9-23_10-12-51.png

    And in the "Unworking area":

    pointerEnter: Pointer (UnityEngine.GameObject)

    upload_2019-9-23_10-13-13.png

    Finally, yes, I added a listener to my button in my
    Start()
    function. In fact, I added two listeners, and is working the same way as only one.
    Code (CSharp):
    1. POI_button.onClick.AddListener(ShowPOI_info);
    2. POI_button.onClick.AddListener(DoubleClick);
     

    Attached Files:

  4. Hellium

    Hellium

    Joined:
    Sep 25, 2014
    Posts:
    43
    Keep your Canvas in the Screen space if you have designed your system this way, but Screen space canvas are not meant to be moved in your scene.

    What is this Pointer gameObject? It is intercepting your mouse events. Uncheck the Raycast Target tickbox on this object and try again.
     
    Sinepsorg likes this.
  5. Sinepsorg

    Sinepsorg

    Joined:
    May 19, 2019
    Posts:
    3
    Hi Hellium,

    It works now ! :D

    Yes, it was my
    Pointer
    gameObject which was intercepting my mouse event. Fyi, it is a kind of sight (a "+" in a text field) designed to reduce motion sickness.

    Many thanks for your help ;)