Search Unity

Audio Best way to load music/effects into game

Discussion in 'Audio & Video' started by Primoz56, Nov 17, 2019.

  1. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    Hi all,

    I've got a game with the usual background music and effects. I've created a script that references/loads all audio from resources on startup and then plays them via audiomanager as needed. Everything works but - the loading times are getting impossibly long, and game 'freezes' during scene loading while music is being loaded, so i can't make any loading bars/scene transitions easily.

    I'd like to know what you've found to be a good way to load/play music/sound in your game and if i'm making any seriously bad mistakes.

    If there's no way to avoid long load times, how can i show a decent loading bar to show progress?

    Thanks,
    Primoz
     
  2. sdochertymusic

    sdochertymusic

    Joined:
    Aug 13, 2019
    Posts:
    8
  3. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    139
    Just adding to this because I don't think it's actually mentioned in the article that was linked previously.

    The freezes you're getting are due to the audio files being loaded on the main resource thread. Check load in background and it won't freeze the game while it loads. Just make sure you load it before you need it.

    I wrote an in-depth article on audio optimisation that you might find helpful, here: https://johnleonardfrench.com/articles/unity-audio-optimisation-tips/
     
    Undume likes this.
  4. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    Thanks guys, will be reading this and putting it to good use soon :)