- Home /
Event.current.Use() not consuming event in editor SceneView
So I have a custom map editor, everything is working correctly except for the painting part. I have the logic correctly laid out and it should be working. However, it still selects the gameobject I clicked on when I called Event.current.Use(); I also tried HandleUtility.AddDefaultControl(0); and still didn't work.
Here is my logic for detecting a click.
 private void OnSceneGUI()
     {
         if (paintingActive)
         {
             //Debug.Log(Event.current);
             if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) && Event.current.button == 0)
             {
                 Debug.LogError("Mouse down or drag");
                 if (currentBrushMaterial != null)
                 {
                     var hits = Physics.RaycastAll(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition));
                     foreach (var hit in hits)
                     {
                         if (hit.collider.gameObject.tag == Tags.terrainBlock)
                         {
                             hit.collider.gameObject.GetComponent<MeshRenderer>().material = currentBrushMaterial;
                             hit.collider.gameObject.GetComponent<EditorMapBlock>().data.terrainType = currentTerrainSelected;
                             Event.current.Use();
                             Debug.Log("Event used");
                             HandleUtility.AddDefaultControl(0);
                             break;
                         }
                     }
 
                 }
                 
             }
         }
     }
I get exactly one log for "Mouse down and drag" and "Event used" for each click; the material is also correctly applied. Can someone help me out here, this should be fairly simple as it is a common use case.
EDIT- I tried to use mouse up instead, still didn't work. It didn't paint at all at the point.
EDIT- I just reread my post and realized it might not be clear what my problem is. I am trying to consume a mouse click event. I call the function Event.current.Use() to accomplish this. It is getting called and everything else works, however, the event is still being raised to select the gameobject I clicked on and am trying to paint inside the SceneView. I need the action of selecting the gameobject to be blocked otherwise I cannot continue painting other objects. Hope that makes sense!
EDIT - I still cant figure this out, some direction would be very appreciated!
EDIT- One more push then I will be posting on forums. Thanks!
Answer by joemane22 · Mar 09, 2020 at 12:38 AM
I found a solution to it which is to use the event SceneView.beforeSceneGui to handle my event processing logic. The code above was generally right however the scene view was processing events before I was which is what was causing the issue.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                