I’m new to addressables. I’m trying to get my music to use addressables since music tracks are some of the larger files in my game, and (in this game) it makes sense to load and unload them separately from the rest of the scene data.
I’ve been following a tutorial, and I figured out how to load an arbitrary file type instead of a game object. So far, it is working. This is what I’ve got:
private void LoadNextSong()
{
if (NextSong == MusicTrack.Silence)
{
return;
}
if (NextSong == CurrentSong)
{
Jukebox.Play();
return;
}
CurrentSong = NextSong;
Addressables.LoadAssetAsync<AudioClip>( GetSongAddress(CurrentSong) ).Completed += SongLoaded;
}
private void SongLoaded(AsyncOperationHandle<AudioClip> obj)
{
if (obj.Status == AsyncOperationStatus.Succeeded)
{
Jukebox.clip = obj.Result;
Jukebox.Play();
}
else
{
Debug.LogError("Failed to load music track!");
GameManager.HUD.BroadcastMessageToPlayer("Failed to load music", 2.5f);
}
}
However, what I can’t seem to find is how to now unload the old song from memory. The tutorials I found just talk about game objects, (and they say that I should release the object instead of destroying it,) but I didn’t load a game object, I just loaded a straight audio clip.
How do I unload the old song from memory?