Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by boogie77 · Sep 11, 2015 at 04:56 PM · audioarraysordersequence

AudioClip Import Order Randomized?

Dragging a number of wave files from assets onto an empty array of AudioClips populates the array in a seemingly random order. Is it possible to have AudioClips in the array be in alphabetical order? With the large number of clips I'm dealing with (well over 1000), it is painful to drag them into the array one by one.... x_X"

 using UnityEngine;
 using System.Collections;
 public class TestAudio2 : MonoBehaviour {
     public AudioClip[] auTest;
         ...
 }

dragging onto array: alt text Array populated with clips in random order: alt text Anyone has any idea how to import them in alphabetical order? ^^

draggingmu.jpg (173.4 kB)
addedmu.jpg (56.9 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 boogie77 · Sep 14, 2015 at 10:08 AM 0
Share
         Debug.Log(audioClips[0].name);

and

         Debug.Log(audioClips[19].name);

for an array of length 20 both write the names properly to the console.

But that also throws the error

ArgumentOutOfRangeException: Argument is out of range.

Parameter name: index

  • it's unusual that both names are written before the error is displayed on the console & the error is thrown on the 1st of the 2 Debug.Logs

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by boogie77 · Sep 14, 2015 at 10:30 AM

hi @Rostam24 thanks for your help! - it's working now with

 System.Array.Sort(auTest,NameSort);

and

 int NameSort (AudioClip a, AudioClip b) {
     return a.name.CompareTo(b.name);
 }

it's from a JavaScript solution for numbers or distances or something that I didn't manage to convert to C# successfully earlier

Ü

Comment
Add comment · 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
1

Answer by Rostam24 · Sep 12, 2015 at 07:11 PM

I would recommend writing a script that will change the order to whatever you want in the Awake() method.

Comment
Add comment · Show 10 · 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 boogie77 · Sep 13, 2015 at 10:44 AM 0
Share

hi @Rostam24 , had been trying that as well but I'm not sure how to do it on C#. certainly

 System.Array.Sort(auTest);

does not work, and I tried other methods too.

I also tried importing AudioSources using

 auTest = GameObject.FindObjectsOfType(typeof(AudioSource)) as AudioSource[]

but it populates the array again, unsorted (and it wouldn't import anything below the topmost layer in Hierarchy either).

can you share how you would do it in C#?

cheers

avatar image Rostam24 boogie77 · Sep 13, 2015 at 10:55 AM 0
Share

I would probably use a List with Linq (but you could probably use an array with Linq as well):

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 
 public class YourClass : $$anonymous$$onoBehaviour
 {
     public List<AudioClip> audioClips;
 
     void Awake()
     {
         audioClips.OrderBy(x => x.name);
     }
 }

I'm sorry, I'm not at home and I can't test it out... So let me know if it works! :)

avatar image boogie77 Rostam24 · Sep 13, 2015 at 01:36 PM 0
Share

Thanks @Rostam24 Ü That doesn't throw any errors or warnings, but the list still remains unsorted. This is puzzling.

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to string multiple audio clips together 1 Answer

Array of AudioClips not playing, please help 3 Answers

How do I save and retrieve ordered data? Can I do this with an array? 1 Answer

¿How Can I fill an array in runtime? 3 Answers

How can I trigger booleans in a specific order? 2 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