Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem with IPointerDown?

Discussion in 'Scripting' started by Zholen, Sep 23, 2016.

  1. Zholen

    Zholen

    Joined:
    Sep 13, 2016
    Posts:
    4
    I was following https://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/panels-panes-windows tutorial to make a draggable panel but I could not get it to work. I am currently using version 5.4.03f of Unity Pro.

    I am looking for an explanation of the following behavior:

    My Steps:
    Create new project 2D
    Add Canvas to scene (leave defaults)
    Add Panel to Canvas
    Create Script called FocusPanel
    Add Code

    public class FocusPanel : MonoBehaviour, IPointerDownHandler
    {
    private RectTransform panel;
    void Awake()
    {
    panel = GetComponent<RectTransform>();
    }

    public void OnPointerDown(PointerEventData data)
    {
    Debug.Log("Pointer Down!");
    panel.SetAsLastSibling();
    }
    }

    Add script to Panel
    Run game
    Click on panel
    See log (Great!)
    Stop game
    Hold shift and resize panel to be something like half the original size, in either or both directions (like he does in the tutorial)
    Run game
    Click on Panel
    No log (!What??)

    Why does OnPointerDown not get called after I resize the panel?
    If I resize the panel back to being just a little smaller than the Canvas it works again, though it seems to fire even if I click on the space outside of the panel. It seems that once the panel is about 2/3 the size of the canvas the event no longer fires.
     
  2. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    That code Works correctly in my computer.

    IPointerDownHandler need EventSystem component to work.
     
  3. Zholen

    Zholen

    Joined:
    Sep 13, 2016
    Posts:
    4
    I have an EventSystem, it currently sits above the canvas in my scene. I was wondering if something got messed up because I did the recent update to 5.3.1 but then had to downgrade.
     
  4. Zholen

    Zholen

    Joined:
    Sep 13, 2016
    Posts:
    4
    I figured out the issue. It seems that if I have un-docked windows there is a chance that the input events stop firing.

    Example:
    Create a second Game tab
    Run game
    In tab 1 click and see log
    In tab 2 click and see log
    Pull tab 2 out of editor to standalone window.
    Click in tab 1, may see log
    Click in tab 2 (now windowed), may see log
    Drag tab 2 back into editor
    Log will now appear from both tabs.

    Only 1 of the two windows will fire the events even though they are both set to the same display. I have also seen that separate windows that are looking at different displays can cause the same effect.