Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Hurr? EventType.MouseUp not working on Left Clicks.

Discussion in 'Scripting' started by orionburcham, Aug 9, 2011.

  1. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    385
    Strange problem. Here's my C# code:

    Code (csharp):
    1.  
    2.  
    3. Event e = Event.current;
    4.                
    5. if(e.type == EventType.MouseUp)
    6. {
    7.     Debug.Log("Mouse Up!");
    8. }
    9.  
    10.  
    This works fine when I right click, and middle click, but not when I left click. A "MouseDown" version of this same code works fine for left clicks. any ideas? I am curfused.

    If anyone feels like it, can you try out the code on your end and see if you get similar results?

    Thanks!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,846
    Works fine here.

    --Eric
     
  3. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    385
    hmm...are you on a pc? I'm on my MBP. maybe that's part of the issue.

    Oh! also, I'm using it in an editor script, so that could be something as well.
     
  4. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    385
    crap, it works fine at runtime. looks like this is an editor problem. probably just have to work around it. :/ Thanks for testing it out.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,846
    No, I'm on a Mac Pro. It works fine in the editor, using a standard OnGUI function anyway.

    --Eric
     
  6. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    385
    Ok, I'be been able to test some of these things to confirm, and it looks like it might be a strange isolated case when using an EditorWindow script with SceneView.OnSceneGUIDelegate. That's the only case where it seems to break, at least so far.

    thanks a lot for the help. I'm going to pursue a workaround for now.
     
    Last edited: Aug 9, 2011
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,846
    I will if you provide some code (too lazy to make an editor script just now...).

    --Eric
     
  8. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Same problem here .. did not check on Mac but on Win7 64.

    Put code in an editor script ( custom editor script )
    and

    click holding the shift key

    Code (csharp):
    1.  
    2.  
    3.  void StartSelection()
    4.     {
    5.         print("start selection");
    6.     }
    7.  
    8.     void EndSelection()
    9.     {
    10.         print("end selection");
    11.     }
    12.  
    13.  
    14.     void HandleEvents()
    15.     {
    16.         Event e = Event.current;
    17.         if (e.type == EventType.MouseDown)
    18.         {
    19.             if (e.shift)
    20.             {
    21.                 StartSelection();
    22.                 e.Use();
    23.             }
    24.         }
    25.         if (e.type == EventType.MouseUp)
    26.         {
    27.             if (e.shift)
    28.             {
    29.                 EndSelection();
    30.                 e.Use();
    31.             }
    32.         }
    33.     }
    34.  
    35.   void OnSceneGUI()
    36.   {
    37.       HandleEvents();
    38.   }
    39.  
    40.  
    41.  

    I get a 'start selection' but no 'end selection' when using left mouse
    I get a 'start selection' and 'end selection' when using right or middle mouse

    even more strange ...

    After one good click (right or middle) , I get one good click with the left mouse button
    before it falls back to the failing behaviour.

    Right button to multi - select control points in my spline for now......

    UPDATE
    -----------

    More people experience the same problem
    http://groups.google.com/group/unity3d-developers/browse_thread/thread/78169691889b8fdd?pli=1

    Hinted is to set some editor setting to .. none , so default move/rotate/scale tool does not capture this mouseUp event...

    anyone knows what setting this would be?
     
    Last edited: Aug 10, 2011
  9. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Found the setting that should do the trick, according to the suggestion in my previous posted link,
    but it did not work. :(

    setting
    Code (csharp):
    1.  
    2. Tools.current = Tool.None;
    3.  
    Does not stop the 'mysterious' object from consuming my MouseUp event.
     
  10. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    2,986
    Did anyone find a fix for this, I to can get no mouseUp event in my OnSceneGUI(). Is there a workaround for this?
     
  11. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
  12. Wenceslao

    Wenceslao

    Joined:
    Feb 7, 2009
    Posts:
    142
    Thank you so much for finding that MADmarine (Thanks to dagbud for the linked post!) It solved the problem I had been struggling with for a couple of nights. Now my tool allows me to populate waypoints in the scene quickly and efficiently and the editor isn't trying to use my input at the same time.
     
  13. vladibo

    vladibo

    Joined:
    Jan 29, 2013
    Posts:
    25
    Code (csharp):
    1.  
    2. void OnSceneGUI(){
    3.        Event e = Event.current;
    4.  
    5.         var controlID = GUIUtility.GetControlID(FocusType.Passive);
    6.         var eventType = e.GetTypeForControl(controlID);
    7.         if (eventType == EventType.MouseUp)
    8.         {
    9.             Debug.Log("Mouse Up!");
    10.             GUIUtility.hotControl = controlID;
    11.             e.Use();
    12.         }
    13.         else if (eventType == EventType.MouseDrag)
    14.         {
    15.             Debug.Log("Mouse Drag!");
    16.             e.Use();
    17.         }
    18.         else if (eventType == EventType.MouseDown)
    19.         {
    20.             Debug.Log("Mouse Down!");
    21.             GUIUtility.hotControl = 0;
    22.             e.Use();
    23.         }
    24.  
    25.  
     
    Murgilod and ocimum like this.
  14. ocimum

    ocimum

    Joined:
    Apr 19, 2015
    Posts:
    12
    This tutorial made my day!
    It explains how to get the different Eventtypes work without losing the focus after clicking on the scene!
     
  15. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    61
    For some reason (which I don't fully understand) the only thing that helped me was adding this line in the beginning of the OnSceneGui method:
    Code (CSharp):
    1. HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive))