Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by syclamoth · Jan 28, 2012 at 04:19 AM · editoreventselection

Preventing editor deselect on MacOS

I'm currently working on a tile-map custom editor, which renders a colour-coded representation of the finished product in the scene view. The editor is working perfectly on my work computer, but as soon as I brought it home in the afternoon one very important function stopped working.

The main interface in the editor is selecting a 'tiletype' from a palette in the inspector, and 'drawing' with the mouse on the grid drawn in the 3D view. The problem is, on the Mac, there seems to be no way to interrupt the default 'deselect' behaviour in the 3D view! So, as soon as you release or drag the mouse, it deselects the current object, and disables the custom editor.

On windows, it was possible to 'eat' the deselect commands with this bit of code (inside OnSceneGUI)-

 if((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && !Event.current.alt)
 {
     Event.current.Use();
 }

This allowed me to rotate the view using 'alt-click', but prevented it from deselecting my objects.

However, on my home computer, it doesn't work! Even using just the raw line

 Event.current.Use();

to attempt to swallow every single event doesn't stop the selection behaviour. I've tried reassigning Event.current, like this-

 Event.current.type = EventType.Ignore;

to disable the event, but even that doesn't work.

At this point I've decided to work on a different part of the project and not worry about it- after all, it's only an editor, and if I can make all of my maps at work it doesn't matter if it's not functional at home. However, the idea of leaving something like this without understanding how to fix it, or even what's going wrong, just seems reprehensible to me.

If anyone else has experience writing complicated custom editors like this, could you please give me some suggestions as to any possible workarounds or fixes for this? Remember, the problem seems only to occur in the MacOS editor- it doesn't happen at all on Windows.

Comment
Add comment · Show 1
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
avatar image syclamoth · Feb 01, 2012 at 06:24 AM 0
Share

I have a small workaround, currently- if I poll for middle-click, ins$$anonymous$$d of left-click, it doesn't deselect things any more. But that's pretty hacky, and I don't like it, so the question remains open.

1 Reply

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

Answer by FredericRP · Jan 25, 2013 at 01:17 PM

You surely got the answer now, but if you're still looking for it, here's the trick : you have to get a control ID for your Custom Editor, then set the default control as this one, see the example below. Be sure that you do that only when the Event is used by your script, otherwise it prevent any action in the scene view (for ex. the scene view gizmo).

 void OnSceneGUI() {
   int controlID = GUIUtility.GetControlID (FocusType.Passive);
   // ... gui stuff
   if (Event.current.type == EventType.Layout) {
     HandleUtility.AddDefaultControl (controlID);
   }
 }
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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Use up a scene selection in the editor. 1 Answer

How does Unity handle GameObject selection in the Scene View? 1 Answer

OnGUI Event 0 Answers

Detecting moment when GameObiect is created in hierarchy. 1 Answer

How to show an Editor Window based upon Selection 1 Answer


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