x


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 ?

more ▼

asked Jan 07 '11 at 05:17 PM

Jeffom gravatar image

Jeffom
228 2 3 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 07 '11 at 05:39 PM

yoyo gravatar image

yoyo
6.5k 25 39 85

this line

EditorGUILayout.ObjectField("Action container", toWaitActionHolder, typeof(GameObject)) as GameObject;

should then show the scene selection tab, but it doesnt :/

Jan 07 '11 at 05:59 PM Jeffom

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.

Jan 07 '11 at 06:05 PM Jeffom

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.

Jan 07 '11 at 08:57 PM yoyo

Disclaimer: I was using Unity 2.6 for my tests. I'll try 3.1 later today.

Jan 07 '11 at 08:59 PM yoyo

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.

Jan 07 '11 at 11:58 PM yoyo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1730
x204
x27

asked: Jan 07 '11 at 05:17 PM

Seen: 2977 times

Last Updated: Jan 07 '11 at 05:17 PM