- Home /
Quickly assigning to array in editor
Let's say you have a public array with 50 variables and you want to assign to each of them a different asset( same type of assets, all are textures but each variable holds a different texture). Is there a way to quickly assign all of the assets to array? And not drag and drop each of them, it can be boring and tedious :)
I would write a script to load in and assign the textures at runtime. It will make it much easier for you and you will not to assign 50 textures.
Answer by robertbu · Apr 17, 2014 at 08:42 PM
Yes and no. If you look in the upper right corner of the Inspector window, you will see a lock symbol. Select the game object that has your array and then click on the lock symbol, that game object will continue to be displayed in the Inspector as you navigate in the Project pane. You can then navigate to whatever you want to populate the list with and select all of your objects and drag and drop them onto the name of the array. This will populate the list all at once. But the problem is the results do not appear to be sorted! So if you are just going to be pulling things out of the array randomly, it works great, but if you need them in the named order, it does not work. Oh so close.
As an alternative, you can put all of your files in a subfolder off of the Assets/Resources folder. Then you can dynamically load them with Resources.LoadAll(). They come in in named order. Or I you could write an editor script to populate your array(s).
Checked this today. In Unity 5.5, when I drug'n'dropped 180 objects to the array name in the inspector, they appeared in a sorted order.
$$anonymous$$y be Unity developers have fixed the issue
Your answer
Follow this Question
Related Questions
Mass assign shaders? 1 Answer
Assign Texture2D at runtime 2 Answers
How can I make my for loop "reset" if my array contains an value? 5 Answers
Automatic SmoothFollow Target Assingment in a SplitScreen Game 0 Answers
AI cannot find closest Target 0 Answers