Community Q&A

Where Wwise users help each other out!

Audiokinetic's Community Q&A is the forum where Wwise users ask and answer questions within the Wwise community. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

How can I make a dynamic playlist which number of elements and order depends on the game state?

0 votes

Hello! I'm working on a little prototype in Unity and I'm struggling with FMOD thinking about a way in which I can program this behavior, so I thought that maybe I could try with Wwise, but I can't find a way either. The mechanic goes like this: the player needs to create a bridge between two islands using blocks. There are 5 blocks, and each has an associated phrase that lasts 1 bar. The player can pick up any of the blocks in any order. When the player positions one of the blocks to start building the bridge, the musical sequence associated with that specific block starts looping (this loop is 1 bar long). When the player picks up any other block and continues the bridge, the musical phrase that corresponds to that block is ADDED AT THE END OF THE PREVIOUS CLIP, and now they both loop like a single unit (that means, from the beginning of the first clip until the end of the second clip, so the loop will be 2 bars long now). If you add any other box to the bridge then this third musical phrase is added at the end of the second clip, and the loop is 3 bars long, etc. In the end, after crossing to the other island you'll be able to hear a 5 bar long musical phrase. You can then demolish the bridge and you will have the 5 boxes again, that you can now use to go back to the first island (or another island). Of course, you can position them in a totally different order, hence the final musical phrase will be different. Here's a graphic I did that tries to explain it a bit clearer.

In the beginning, I thought I could replicate the behavior with a playlist (so not in the Music Hierarchy, but in the Actor Hierarchy), with 5 slots and switches in each slot to change clips depending on what box the player picks. The problem is that the number of slots in a playlist is static. If the player grabs one box, the playlist should be only one item long, when he grabs a second, the playlist should be two items long, and like that, items should be added one by one each time the player grabs a new box. I can't think of any way of achieving this behavior, but I have the feeling there must be some workaround that I haven't thought about yet. Any ideas?

I know this is a lot of text that maybe only makes sense in my head, so I made a little graphic to try to explain the desired behavior better. Many thanks in advance.

asked Jan 29 in General Discussion by Gabriel G. (110 points)

1 Answer

0 votes

Hey Gabriel, 

Do you need all of this to loop from posting the Event once? 
If not, then maybe you could reuse the same Music Switch Container in Wwise and post it separately on each "block" and use the EndOfEvent callback to know when to call the next block? 

That said, to keep track of this mechanism from the game side as well, I would probably control it with a List where you add each selected block to. 
Here's a quick suggestion of such a script. It first adds all the blocks being picked using OnAddingBlock() and then when you start it with ActivateBlock() it runs until there are no more blocks in the list.
* If you need to learn more about Callbacks, you should take a look in the Wwise-301 course


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlockController : MonoBehaviour
{
    public List<GameObject> blocks = new List<GameObject>(); // The List
    public int CurrentBlocNumber = 0; 
    public AK.Wwise.Event MusicSwitchContainer; // Would work fine with just an Actor Mixer Switch Container instead. 
    public AK.Wwise.CallbackFlags callbackForcingNext; // Just pick EndOfEvent here. 


    public GameObject Block01;
    public GameObject Block02;
    private void Start() // This function is just for test purposes.
    {
        OnAddingBlock(Block01, "Block01");
        OnAddingBlock(Block02, "Block02");
        ActivateBlock();
    }

    void OnAddingBlock(GameObject theBlockToAdd, string nameOfBlockSwitch) {
        AkSoundEngine.SetSwitch("BlockGroup", nameOfBlockSwitch, theBlockToAdd); // only needs to be set once you add block
        blocks.Add(theBlockToAdd); // add block to end of list.
    }

    void ActivateBlock() {
        // Post Event + callback.
        MusicSwitchContainer.Post(blocks[CurrentBlocNumber], callbackForcingNext, CallbackFunction);
        CurrentBlocNumber++;
    }

    void CallbackFunction(object in_cookie, AkCallbackType in_type, object in_info)
    {
        // if there's blocks left in the list, then activate next one.
        if (CurrentBlocNumber < blocks.Count) {
            ActivateBlock();
        }
    }
}


Let us know if this is helpful.

answered Feb 1 by Mads Maretty S. (Audiokinetic) (12,300 points)
...