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
0
Question by zero3growlithe · Dec 12, 2012 at 12:07 PM · bugplayfilesread

DirectoryInfo().GetFiles works incorrectly in Standalone

So, i'm making adding your own music possible in my game and i hit a problem which is: I'm using a function to look for a folder, search for files in it, save them in array and play them in random order. It works perfect in unity editor but when i compile it for standalone, it is not so cool... i debugged what does GetFiles() function return in both cases and i got:

full file path + filename - in editor && only filename in standalone

so I'm assuming that it is an internal unity bug as some other things stopped working for me after Unity 4 came to my PC... here's code I'm using:

 private var IsAnyMusicInFolder : boolean = false;
 private var CheckMusicFolder : boolean = false;
 private var ReadyToPlay : boolean = false;
 private var MusicPlaying : boolean = false;
 var MusicTrackID : float = 0;
 private var NoMusicTimer : float = 0;
 private var RandMusicID : float = 0;
 private var ExtMusicFile : WWW;
 function LoadMusicFromMusicFolder (){
     if (Directory.Exists(Application.dataPath+"/Music")){var info = new DirectoryInfo(Application.dataPath+"/Music");}
     if (!info){CheckMusicFolder = true;}else{
         if (!CheckMusicFolder){var fileInfo = info.GetFiles("*.ogg");}
             if (!CheckMusicFolder && fileInfo.length > 0){
                 MusicAssignIDRandomizer.Clear();
                 IsAnyMusicInFolder = false; ReadyToPlay = false; MusicTrackID = 0;
                 MusicFilesFromExtSrc = new String[fileInfo.length];
                 for (i=0; i < fileInfo.length; i++){
                     RandMusicID = Random.Range(0, MusicFilesFromExtSrc.length);
                         if (ArrayUtilityInt(RandMusicID, MusicAssignIDRandomizer) == false){
                             MusicFilesFromExtSrc[i] = fileInfo[RandMusicID].ToString();
                             Debug.Log (MusicFilesFromExtSrc[i]);
                             MusicAssignIDRandomizer.Add (RandMusicID);
                         } else {i--;}
                 }
                 IsAnyMusicInFolder = true; CheckMusicFolder = true;
             } else {CheckMusicFolder = true;}
             if (CheckMusicFolder && IsAnyMusicInFolder){
                 if (!ReadyToPlay){
                     Destroy(audio.clip);
                     ExtMusicFile = new WWW ("file://"+MusicFilesFromExtSrc[MusicTrackID]);
                     //else{ExtMusicFile = new WWW ("file://"+Application.dataPath+"/Music/"+MusicFilesFromExtSrc[MusicTrackID]); Debug.Log("file://"+Application.dataPath+"/Music/"+MusicFilesFromExtSrc[MusicTrackID]);}
                     audio.clip = ExtMusicFile.GetAudioClip(false, false);
                     ReadyToPlay = true;
                 }
                 if (!audio.isPlaying){NoMusicTimer += Time.deltaTime;
                     if (NoMusicTimer > 0.1 && audio.clip.isReadyToPlay){Debug.Log("Fuck");audio.Play();}
                 }  else {NoMusicTimer = 0;}
                 if (audio.clip.length-audio.time<0.5 && audio.isPlaying){
                     if (MusicTrackID < MusicFilesFromExtSrc.length-1){
                         MusicTrackID++;
                     } else {CheckMusicFolder = false;}
                     ReadyToPlay = false;
                 }
                 if (Input.GetKeyDown("/")){
                     if (MusicTrackID < MusicFilesFromExtSrc.length-1){
                         MusicTrackID++;
                     } else {CheckMusicFolder = false;}
                     ReadyToPlay = false;
                 }
             }
     }
 }
 function ArrayUtilityInt (RandNumber : float, ObjArray : Array){
     for (i = 0; i < ObjArray.length; i++){
         if (ObjArray[i] == RandNumber){
             return true;
         }
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Landern · Dec 12, 2012 at 01:30 PM

DirectoryInfo().GetFiles() returns an array of FileInfo type... if you don't need all the extra weight in the type and you only want the *.ogg files as an array of string, just use:

 ....
 var somePathStrings : String[] = Directory.GetFiles(someDirectoryPath, "*.ogg");
 ....
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 ArkaneX · Dec 06, 2013 at 02:20 PM

Please use this

 fileInfo[RandMusicID].FullName

instead of

 fileInfo[RandMusicID].ToString()
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

11 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

Unity-workspace gets Black when starting game 0 Answers

Unity plays imported animations incorrectly 1 Answer

i get weird rotations on my animated objects using legacy, help? 0 Answers

More Unity bugs, sometimes it keeps restarting character position to (0,0,0) 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