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 Tofudude624 · Mar 15, 2012 at 08:08 AM · arrayaudio

Array of audio clip arrays?

I have an a few arrays of audio clips. Can I put all of those arrays into one big array? I know you can have several arrays of integers make up one larger array, but I am not quite how to put one type of array into another...Thanks

Comment
Add comment · Show 2
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 syclamoth · Mar 15, 2012 at 08:26 AM 0
Share

Unity does not support serialized multi-dimensional or jagged arrays. Unless you write your own classes that manage this kind of thing, I'm afraid you're out of luck. Otherwise, do a search on this site for multidimensional arrays, and I'm sure you'll find something you can use.

avatar image FLASHDENMARK · Mar 15, 2012 at 08:46 AM 0
Share

This is not the same thing as arrays, but you could put all of your arrays into a class.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fherbst · Mar 15, 2012 at 08:57 AM

As syclamoth pointed out, Unity can't serialize (save) moredimensional arrays. The workaround is putting your "inner" array into a class and have an array of this class.

Copy the following code into a new script "MyAudioClipHolder.cs" and see for yourself how this behaves in the editor:

 using UnityEngine;
 using System.Collections;
 
 // System.Serializable lets you change this class in editor
 [System.Serializable]
 public class AudioClipArray {
   // your "inner" array
   public AudioClip[] clips;
 }
 
 public class MyAudioClipHolder : MonoBehaviour {
   // the "outer" array
   public AudioClipArray[] clipArrays;
 }
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
0

Answer by ow3n · Jul 04, 2017 at 04:49 PM

I realize I am resurrecting an ancient post but after a long search I want to acknowledge how helpful the answer by @felix. was; as well as to share how I implemented it. If you use it wrong you will get the following error:

error CS0021: Cannot apply indexing with [] to an expression of type `AudioClipArray'

So, in a SoundController.cs file...

 using UnityEngine;
 using System.Collections;
      
 // System.Serializable lets you change this class in editor
 [System.Serializable]
     public class AudioClipArray {
     // your "inner" array
     public AudioClip[] clips;
 }
      
 public class SoundController : MonoBehaviour {

     // the audio component on the GameObject this script is attached to
     private AudioSource audio;
     // multi-dimensional array of all the sounds 
     public AudioClipArray[] clipArrays;

     void Start(){
         // play the sound (note the ".clips" reference there)
         audio.PlayOneShot (sounds[int1].clips[int2], .5);
     }
 }







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

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

Randomize Audio Clip 1 Answer

Playing a soundclip at random from an array. C# 2 Answers

make audio array and play random 1 Answer

Play sound from an array, not random, and only once 3 Answers

[URGENT] WebGL export completely different from editor playtesting. [C#] 1 Answer


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