• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joemane22 · Mar 07, 2020 at 11:42 PM · editoreditor-scriptingeventsystemeventsevent-handling

Event.current.Use() not consuming event in editor SceneView

So I have a custom map editor, everyt$$anonymous$$ng 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 $$anonymous$$ts = Physics.RaycastAll(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition));
                     foreach (var $$anonymous$$t in $$anonymous$$ts)
                     {
                         if ($$anonymous$$t.collider.gameObject.tag == Tags.terrainBlock)
                         {
                             $$anonymous$$t.collider.gameObject.GetComponent<MeshRenderer>().material = currentBrushMaterial;
                             $$anonymous$$t.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, t$$anonymous$$s 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 t$$anonymous$$s. It is getting called and everyt$$anonymous$$ng 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 t$$anonymous$$s out, some direction would be very appreciated!

EDIT- One more push then I will be posting on forums. Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by joemane22 · Mar 09, 2020 at 12:38 AM

I found a solution to it w$$anonymous$$ch 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 w$$anonymous$$ch is what was causing the issue.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I handle multiple buttons and their event triggers ? 0 Answers

Why does my code hang when calling a script in a multi-nested event function 0 Answers

Unity Editor Scripts: GameObject Added / Removed Event? 1 Answer

Trigger an event from editor script? 0 Answers

Unity 2019.3 any way to make mouse events pass thru an UI element without disabling "Raycast Target" ? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges