Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DannyB · Jul 08, 2012 at 12:32 PM · inspector

Dragging multiple assets to inspector

Hello all,

I have a script with a public Textures[] array attached to an object. I was happy to see that I can select my 24 texture files, and just drag them onto the Textures field in the inspector. It automatically increased the array size to 24 and applied all textures to the array elements.

However, the result was unusable, since it did not maintain any order. My textures are named walk0001 to walk0024 but the resulting order was completely random.

Screenshot:

alt text

Anything I am missing? Or is it just not possible to drag multiple assets in an organized fashion?

20120708152752.png (23.7 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kutulue · Jun 08, 2013 at 07:27 AM 0
Share

Im getting the same issue.

I have discovered it is due to the way the images or objects are imported into unity. If you use an explorer and select 100 items named item01,item02 etc and drag and drop them into unity. They will then appear in random order when dragged into a public array.

If the items are dragged into Unity one at a time e.g. item01 dragged and dropped, then item02 etc. The items will then drag in the correct order to the public array.

Unfortunately this bug removes a lot of the use of being able to drag into a public array.

Hope Unity can fix it soon. Getting sick of filling 200+ arrays one by one.

I guess I should spend the time to make a UI script that handles it.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by JoeStrout · Apr 20, 2015 at 04:55 PM

FWIW, in case somebody else stumbles across this question as I did, here's the solution I have settled on for now. In the script containing an array property, add a bit of code to create a contextual menu, like this:

 [ContextMenu ("Sort Frames by Name")]
 void DoSortFrames() {
     System.Array.Sort(frames, (a,b) => a.name.CompareTo(b.name));
     Debug.Log(gameObject.name + ".frames have been sorted alphabetically.");
 }

In this example, I have a "public Sprite[] frames" property; just change all occurrences of "frames" to whatever your own array property is, and it ought to work. (Also, this is C#; changes would be needed for JavaScript.)

This lets the designer decide when they want to sort, by right-clicking the script and choosing the new "Sort" command the above code adds to the contextual menu.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nacs · May 24, 2015 at 08:36 PM 1
Share

Nice simple solution that works great. Thanks!

avatar image
0

Answer by saschandroid · Feb 18, 2014 at 01:59 PM

I don't know if this is still useful for anybody, but I had the same "problem" and fixed it by sorting the Texture2D-array at Start().

 // Texture array
     public Texture2D[] m_textures;
 // 0-based starting position of numbers in image name
     public int m_numStart;
 // Length of the number part the image name
 public int m_numLength;

 private void Start ()
 {

     sortTexturesByNumber(m_textures, m_numStart, m_numLength);

}

 private Texture2D[] sortTexturesByNumber(Texture2D[] f_textures, int f_index, int f_length)
 {
     for (int i = 1; i < f_textures.Length; i++)
     {
         int j = i;
         while (j > 0)
         {
             string l_nameOne = f_textures[j - 1].name.Substring(f_index, f_length);
             string l_nameTwo = f_textures[j].name.Substring(f_index, f_length);
             if (int.Parse(l_nameOne) > int.Parse(l_nameTwo))
             {
                 Texture2D l_temp = f_textures[j - 1];
                 f_textures[j - 1] = f_textures[j];
                 f_textures[j] = l_temp;
                 j--;
             }
             else
             {
                 break;
             }
         }
     }
     return f_textures;
 }

So if your images have names like "image####.png", m_numStart = 5 and m_numLength = 4.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kutulue · Feb 21, 2014 at 01:17 AM 0
Share

Thanks saschandroid.

I have not tried out the code yet. But it looks like it does solve the issue.

Will test it out shortly.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I create a JavaScript class that creates an object with viewable variables in the inspector? 3 Answers

Why is my class hidden in inspector with C# and not JS? 1 Answer

Mask field in the editor 8 Answers

reseting inspector value automatically 1 Answer

Particle emitter 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges