Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

MouseDownEvent only registers right mouse click

Discussion in 'UI Toolkit' started by nilsdr, Jun 3, 2019.

  1. nilsdr


    Oct 24, 2017

    I'm using the new UI Elements framework to create some editor tools. Somehow if I add a button and register an event handler (as per the docs) it only registers a right mouse click.

    Code (CSharp):
    1. Button batchBuildButton = new Button();
    2.         batchBuildButton.RegisterCallback<MouseDownEvent>(evt => {
    3.             Debug.Log("Batch build...");
    4.             foreach(KeyValuePair<ByARConfig, SerializedObject> kvp in configs)
    5.             {
    6.                 buildAndroidPlayer(kvp.Key, true, false);
    7.             }
    8.         });
    9.         batchBuildButton.text = "Batch build Android (prod)";
    Is there something I'm missing? The documentation speaks of buttons having either default actions or event handlers, do I have to prevent the default action somehow?
  2. uMathieu


    Unity Technologies

    Jun 6, 2017
    Button classes uses a Clickable manipulator internally which eats the MouseDown event and prevents its propagation. To have your callback called when the mouse is clicked, try this:

    batchBuildButton.clickable.clickEvent += () => {...};

    or pass your delegate straight to the Button's constructor.
    baixiaoxi likes this.