Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Tehelee · Oct 11, 2013 at 07:53 PM · c#guieditorobject

How do I use EditorGUIUtility.ShowObjectPicker()? C#

http://docs.unity3d.com/Documentation/ScriptReference/EditorGUIUtility.ShowObjectPicker.html

No code example, documentation is vague, and google yields nothing. Anyone know what they're doing with this?

Also why couldn't it be: Object ShowObjectPicker( ObjectClass class, bool showSceneObjects )

As it is a unity editor function, I assume that's the most streamlined method. (Most everything else in editor is thread pausing, why not the object picker?)

Comment
Add comment · Show 2
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 Fornoreason1000 · Nov 22, 2013 at 05:30 PM 0
Share

you can call it from OnGUI() for editor scripts and it will show up.

  EditorGUIUtility.ShowObjectPicker<UnityEngine.GameObject>(new UnityEngine.Object(), false, " ", 2);

as for applying it for practical use, the docs still have no information. I have discovered that you can filter objects by providing the type in the , t talks about messages, but no messages get receive that corresponded to the docs, also it talks about an ExecuteCommand event that i should receive, i found something similar to that (EditorGUIUtility.CommandEvent) which returns an event i tried to apply the

 `EditorGUIUtility.GetObjectPickerObject();`

in OnGUI but no avail (Null Reference, UnityEngine has no idea what ShowObjectPicker I'm talking about). I'm interested in finding out on how to use it.

avatar image hklown · Nov 26, 2013 at 08:37 PM 0
Share

Also with regards to the question about why the object picker can't be a blocking call- most GUI stuff is in fact not blocking (nor should it be). Though I do agree that the way they chose to implement getting the return value from the picker isn't the greatest.

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by hklown · Nov 26, 2013 at 07:26 PM

To act on the "events" provided by the object picker, try this somewhere in the body of your OnGUI method:

 if (Event.current.commandName == "ObjectSelectorUpdated")
 {
      // do a thing relating to the object picker
 }

Take a look at the Event class for some more info about consuming the events posted by the Object picker.

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
avatar image
3

Answer by ecesis_llc · Feb 22, 2016 at 12:20 AM

I was still not sure how you use the control ID for a picker window. Here is what I did to get multiple object fields working with the picker.

Use the following code to open up a picker window with a specific control ID.

 //in your EditorWindow class
 
 int currentPickerWindow;
 
 void ShowPicker() {
     //create a window picker control ID
     currentPickerWindow = EditorGUIUtility.GetControlID(FocusType.Passive) + 100;
 
     //use the ID you just created
     EditorGUIUtility.ShowObjectPicker<GameObject>(null,false,"ee",currentPickerWindow);
 }

Then, in your method that draws the object field check for the event commandname "ObjectSelectorUpdated" and check if the open picker has your custom controlID. EditorGUIUtility.GetObjectPickerObject() should be the picker object you want.

 Object effectGO = null;
 
 if( Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow )
 {        
     
     effectGO = EditorGUIUtility.GetObjectPickerObject();
     currentPickerWindow = -1;
 
     //name of selected object from picker
     Debug.Log(effectGO.name);
 }
Comment
Add comment · Show 3 · 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
avatar image Ash-Blue · Aug 22, 2017 at 05:43 AM 0
Share

The usage of control IDs makes this the correct answer I$$anonymous$$O. Not safe to use the picker window otherwise.

avatar image Maxi3000 · May 01, 2019 at 05:22 PM 0
Share

Yes, the usage of the control ID is very good. Also added the following lines, just for safety reasons.

 if (Event.current.commandName == "ObjectSelectorClosed") {
             currentPickerWindow = -1;
 }
avatar image Long2904 · Feb 23, 2021 at 12:17 PM 1
Share

Just for curious, can I call GetObjectPikerObject() when commandName is "ObjectSelectorClosed"? Like when I double-click to choose an object in the selector and it's automatically closed. Is this when commandName is "ObjectSelectorClosed"?

avatar image
0

Answer by Probe-Games · Dec 18, 2013 at 08:35 PM

This really pissed me off. That goddamn showobjectpicker.

Anyways, I found a script from some Japanese place that works. He basically made it looked at normal objects. I only changed it to Texture2D.

So if you check here and just change the Object texts to Texture2D. It'll work.

http://anchan828.hatenablog.jp/entry/2013/11/15/143139

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

22 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

Related Questions

Editor Scripting Input Problem OnGUI() 1 Answer

Update variables with C# properties in customeditor 2 Answers

How to solve the problem of "You are pushing more GUIClips than you are popping" 1 Answer

Trying to change a subclasses' variable 1 Answer

Add Dropdown Menues and Checkboxes to custom Editor windows 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