How to create your first Playlist

This continues from where we left off with How to play a sound effect from a collision. Make sure you've done those steps first.

Playlists are used to create music soundtracks for your game. There are a ton of features built in without requiring any coding at all.

     
  1. Locate and select the Master Audio game object in the Scene. Go down to the Playlists section. Expand it if it isn't already by clicking the arrow.
     
  2.  
  3. We need 2 things to create a Playlist. We need a Playlist Controller (to host and play the Playlist) and the Playlist itself, which is the songs you want to play. Click on those links to learn more about what's possible! To create the Playlist Controller, click the "Create Playlist Controller" button. It's called "PlaylistController" default. If you want to rename it, select it in the Hierarchy and rename it. Now you can see the Playlist Controller's settings such as its Initial Playlist.
     
  4.  
  5. Now we can create the Playlist itself. Click "Add" in the Playlists section at the bottom and you will see the following section appear.
     
  6.  
  7. Now go ahead and drag some music Audio Clips from Project view into the yellow drag area to create songs for the Playlist. Normally for Playlists you won't want to use Audio Clips for memory considerations, so read about other options on the Audio Origins page. Here's how it looks after I've added a couple.
     
  8.  
  9. For each song, go ahead and set individual pitch, volume, loop and other song settings.
  10.  
  11. Scroll back up above the songs to "Playlist Controller Setup" and select your Playlist for "Initial Playlist" so that the Playlist Controller will know which Playlist to play intially. And yes, you'll eventually want to hook up the Audio Mixer Group from your Unity Mixer Asset shown here.
     
  12.  
  13. Now let's look at some other settings on the Playlist Controller by navigating to its Game Object. You do that by clicking the gear icon in Playlist Controller Setup.
     
       
    • Start Playlist On Awake: This field controls whether the Playlist automatically starts playing when you enter Play mode. Otherwise you can manually start it later.
    •  
    • Shuffle Mode: This will play songs in random order instead of the order they appear in the Playlist.
    •  
    • Loop Playlists: If this is on, Playlists will "refill the song pool" after all songs have been played to keep playing music.
    •  
    • Auto advance clips: If this is on, when a non-looped song finished playing, it will play the next song, if any are left.
  14.  
  15. Now you're ready to hit play and see the Jukebox! This shows the status of the Playlist and has CD Player type controls.