- Home /
why I Cant Add Multiple Objects to the "Object Field" in Editor Window?
I have an Object field in my editor window. I can add single objects from hierarchy. However I cannot do the same when I select multiple objects and drag&drop them into the object field. Isnt it possible, or is there any other way?
Answer by DannyB · Oct 26, 2013 at 12:10 PM
If you want to assign multiple objects to a field, this field needs to be an array, like Object[]
or GameObject[]
Can you please give an example of how this would look in code? Im trying to do this right now and am having dificualty finding any information on this anywhere.
Answer by foomanchu1989 · Apr 04, 2016 at 04:13 AM
@veddycent @simsis3d
What you want is not possible but you can do this however. You can detect when the user has dropped the items into the field and then you can use this field to get what objects were selected at the time of the drop:
Selection.gameObjects
A snippet from what I used:
GameObject tempObject; tempObject = (GameObject)EditorGUILayout.ObjectField(tempObject, typeof(GameObject), true);
if (tempObject != null)
{
if (Selection.gameObjects.Length > 1)
{
// Do multiple stuff here
}
}
Answer by RandyLarson · Jan 20, 2019 at 02:27 PM
ObjectField
does not have a variant that targets and array of UnityEngine.Object
. This answer will accomplish what you are looking to do:
Your answer
Follow this Question
Related Questions
Too much space between EditorGUILayout.SelectableLabel 2 Answers
EditorGUILayout.ObjectField does not allow me to select a script. 1 Answer
Create a custom editor window with repeating subsection (mockup included) 0 Answers
Array of objectFiled in editorWindow 1 Answer
Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer