- Home /
custom editor EditorGUILayout.ObjectField only shows the assets folder
When i click the field to select the object it only shows the assets folder objects . Is there any way to show the scenes tab ?
Answer by yoyo · Jan 07, 2011 at 05:39 PM
EditorGUILayout.ObjectField takes a parameter to specify which type of object to select.
In Unity 2.6.1 you can use ...
- typeof(UnityEngine.Object) -- only shows assets in the selection menu, but you can drag/drop game objects from the scene
- typeof(GameObject) -- selection menu lets you choose from all your game objects in the scene (and no longer get to choose from assets)
- typeof(BuiltInComponent) -- lets you select from all components of this type in the scene
- typeof(ScriptedComponent) -- gives you a large number of objects to choose from, but only accepts ones that have your custom component attached (seems like there's a minor bug)
In Unity 3.1, the selector is much nicer -- a tabbed dialog with preview instead of a huge long menu -- BUT it always restricts the view to assets. The fact that it's tabbed makes it look like it should should support other groups of objects, but it's not there yet. Not sure if this is a bug or a missing feature. I added a feature request here, vote for it if you want it fixed.
this line
EditorGUILayout.ObjectField("Action container", toWaitActionHolder, typeof(GameObject)) as GameObject;
should then show the scene selection tab, but it doesnt :/
correct me if i'm wrong but the typeof( Type ) field is only to filter the object with the type you want on the selection ,it doesn't really enables or disables the selection from scene or assets.
By setting the type parameter, you control what (types of) objects can be selected. If you use a type that is a native of the scene view (like GameObject or Component) then you will be able to select from objects of that type that are currently in the scene. If you simply use typeof(Object) then you only see objects (assets) from the Project list -- which seems like a bug, but that's how it works. Try it and see.
Disclaimer: I was using Unity 2.6 for my tests. I'll try 3.1 later today.
Hmm, looks like 3.1 has a better interface, but less functionality. I edited my answer with details and the link to a new feature/fix request.
Your answer
Follow this Question
Related Questions
EditorGUI.ObjectField not working properly in a editor window? 0 Answers
OnGUI elements in editor scene view 1 Answer
editor target cast fail on DLL 0 Answers
CustomEditor for TextureImporter? 2 Answers
Color custom editor window ? 2 Answers