- Home /
How to drag in gameObject to public gameObject array property
This is probably a silly question, but how am i supposed to drag in a game object to a public game object array in the Unity editor????
I really can't figure it out
When i try to change size, it just changes back to 0
public variable declaration:
public GameObject[] Hazards;
Please help. thanks
Drag it to the name of the array, and the cursor will have a little plus sign on it. It will automatically add the index and the gameobject. You can do this with multiple objects if order doesn't matter.
Answer by justin35f · Dec 15, 2014 at 01:14 AM
An array needs it's size initialized before it can be used. What you can do is click into the size property where the 0 is and change it to however large you need. If you are having an issue doing this, make sure you press enter after you change it. Sometimes the editor is a bit finicky and resets a value if you don't press enter.
Once you change the size, you'll see several slots open up below (the same number as you just typed in) and you can then drag your object into those slots.
You don't need to do this; you can just drag an item (or multiple items) onto the array name. Unity will add the items to the array automatically, and the number will change to reflect how many items are in the array.
Yes, I understand that it is possible to drag directly onto the name. If you watch the video, that isn't working though, so I offered an alternate solution.
This solution worked, and i also discovered that the problem was because of my prefab :) (because Unity crashed a little while before) . i can't drag it in the scene or slots anymore. but that's no problem. i'll fix that. THAN$$anonymous$$S!
Your answer
Follow this Question
Related Questions
Can a GameObject inside of an array be made "accessible" from the editor? 2 Answers
Unload from memory - GameObject in an array? 1 Answer
How to set to game objects's position from 2 different game objects arrays equal to each other? 0 Answers
How would you override Editor object dragging? 0 Answers
Any way to lock an object from changes in the editor? 4 Answers