- Home /
How can I restrict the object selection to prefabs only?
Is there any way to constraint the possible selection of GameObjects in an ObjectField (EditorGUILayout.ObjectField) to Prefabs only?
Answer by dubbreak · Feb 14, 2013 at 05:12 PM
Just set allow scene objects to false? That will limit it to assets (i.e. not object in the scene).
You can determine if an object is a prefab (in the editor not at runtime.. but you are working in the editor) using this: How to know if a GameObject is a prefab?. Since ObjectField doesn't have a way to edit the list or do better filtering you'd have to roll your own object selector (other than object type and prefab isn't a type).
Thanks, I saw that. One would think that there is an easy way to do this...
I'll roll my own selector, then...
I'm disappointed at the lack of events. You'd think there'd be some way to catch an event and filter the results.
Yes, that would indeed help. They've already the ObjectField... A supplementary parameter for a filter function would be great :)
I know that this is an old question but, is there a way to do the opposite? I need my GameObject selection to only allow objects that are in the scene.
Your answer
Follow this Question
Related Questions
Is there any way to associate a "custom asset" with a particular file type? 1 Answer
[CanEditMultipleObjects] doesn't actually work for an ObjectField? 2 Answers
EditorGuiLayout - Objectfield 1 Answer
Are there any Editor fields which are Drag and Drop? 0 Answers
How to Find Assets of the Same Type in Editor Script 1 Answer