- Home /
Delete sound assets during gameplay?
I'm making a game where the user dynamically adds objects and saves them to come back to, I currently have it all figured out after many a nights tinkering with serializing, well I have got how to save a recording to a wav file and how to call that back during gameplay, but how do I delete that file? Let's say a user makes a song and wants to delete it after a couple of days to make space, I'd like to delete the sounds from his device as well as the serialized strings to stop the game from being a memory consuming monster, any ideas on how to go about this? Or any links that explain it? It must be during gameplay so Editor scripts for sure won't work.
I think by some method you need to over right the file with the same name. Like you have created a file name '1.wav' and then you are going on with increment ( i.e. 2,3,4,...N). now you have to delete 1 so now you have to recreate a file named 1.wav so that the new updated file should be over write the old file.
I dont know any other solution. :(
I was thinking about doing that actually if I can't get File.Delete to work (which so far I haven't been able to), any ideas getyour411? I'm using System.IO and I put File.Delete(file.path + file Name) in my code and I even debug the file path and file name to make sure it's matching but alas no avail, it won't delete, though it's debuging the right file path.
Answer by NeverHopeless · Aug 17, 2015 at 06:31 AM
You can try like this to delete the sound file created:
System.IO.File.Delete(yourFilePath);
I'm trying to, I'm using System.IO and I put File.Delete(file.path + file Name) in my code and I even debug the file path and file name to make sure it's matching but it won't delete, though it's debuging the right file path.
There are few conditions when the Delete
function is expected to work but it appears never working. Please check if you have any of these conditions:
http://stackoverflow.com/questions/2025482/file-delete-not-deleting-the-file
http://stackoverflow.com/questions/6391711/how-to-delete-a-file-after-checking-whether-it-exists
No that's not it, do you think maybe it's because I'm deleting the game object after deleting the sound assets associated with it, and the game object is destroyed and code stops running because of that? I'm trying a coroutine now with a yield return wait for seconds(3f) but that still isn't working
I finally got it to work, turns out I wasn't putting + ".wav" after the file path, so it was never really finding it, I know, I am indeed a dumb ass, but I'm learning lol. Thanks for your help!
Your answer
