Forum rules - please read before posting.

Wwise Actions

I know there's a thread about wwise integration, however, I felt it would be better to create a new thread rather than revive a dead, two year old, thread.

With Wwise opening up a bit more for indie devs, I've been toying with it a bit more and needed some actions. So here are a few that I threw together:
Note* All actions allow you to select things directly via the wwise picker

Load/Unload a Soundbank:
(Select the bank you want to deal with, then select whether you want to load or unload it)

`
using UnityEngine;
using System.Collections.Generic;
using AK;
using AK.Wwise;

if UNITY_EDITOR

using UnityEditor;

endif

namespace AC {
[System.Serializable]
public class AK_LoadSoundbank : Action {
public override ActionCategory Category { get { return ActionCategory.Custom; }}
public override string Title { get { return "Load Soundbank"; }}
public override string Description { get { return "Load a WWise Soundbank"; } }

    public Bank mySoundBank;
    public enum loadUnload {
        Load,
        Unload
    };
    public loadUnload bankEvent;


    public override float Run () {
        if (bankEvent == loadUnload.Load) {
            mySoundBank.Load();
        } else {
            mySoundBank.Unload();
        }

        return 0f;
    }

    #if UNITY_EDITOR

    public override void ShowGUI () {
        if (this == null)
            return;

        var serializedObject = new SerializedObject(this);
        serializedObject.Update();
        SerializedProperty myBank = serializedObject.FindProperty("mySoundBank");
        EditorGUILayout.PropertyField(myBank, true);
        bankEvent = (loadUnload)EditorGUILayout.EnumPopup("Action:", bankEvent);

        serializedObject.ApplyModifiedProperties();

    }
    #endif
}

}`

Change Wwise Switch
(Select the new switch you want to switch to)

`using UnityEngine;
using System.Collections.Generic;

if UNITY_EDITOR

using UnityEditor;

endif

namespace AC {
[System.Serializable]
public class AK_Switch : Action {

    // Declare properties here
    public override ActionCategory Category { get { return ActionCategory.Custom; }}
    public override string Title { get { return "Set Audio Switch"; }}
    public override string Description { get { return "Call Audio Switch Event."; } }

    public AK.Wwise.Switch switchToSet;

    public override float Run () {
        switchToSet.SetValue(GameObject.Find("WwiseGlobal"));
        return 0f;
    }

    #if UNITY_EDITOR
    public override void ShowGUI () {
        if (this == null)
            return;

        var serializedObject = new SerializedObject(this);
        serializedObject.Update();
        SerializedProperty switchEvent = serializedObject.FindProperty("switchToSet");
        EditorGUILayout.PropertyField(switchEvent, true);

        serializedObject.ApplyModifiedProperties();
    }
    #endif
}

}`

Call a Wwise Event
(Select the event you want to call. Select if it's a player as the object, or set the gameobject making the call. If left empty, it will just pass in the WwiseGlobal gameobject that should be auto generated in the scene)

`using UnityEngine;
using System.Collections.Generic;

if UNITY_EDITOR

using UnityEditor;

endif

namespace AC {
[System.Serializable]
public class AK_PlayAudioEvent : Action {
public override ActionCategory Category { get { return ActionCategory.Custom; }}
public override string Title { get { return "Play Audio"; }}
public override string Description { get { return "Play an audio event."; } }

    public AK.Wwise.Event eventToCall;
    public bool isPlayer;
    public GameObject sender;

    public override float Run () {
        if (sender == null) {
            sender = GameObject.Find("WwiseGlobal");
        }
        if (isPlayer) {
            sender = KickStarter.player.gameObject;
        }

        eventToCall.Post(sender);
        return 0f;
    }

    #if UNITY_EDITOR

    public override void ShowGUI () {
        if (this == null)
            return;

        var serializedObject = new SerializedObject(this);
        serializedObject.Update();
        SerializedProperty audioEvent = serializedObject.FindProperty("eventToCall");
        EditorGUILayout.PropertyField(audioEvent, true);

        isPlayer = EditorGUILayout.Toggle(new GUIContent("Player?"), isPlayer);

        if (!isPlayer) {
            sender = (GameObject)EditorGUILayout.ObjectField("Source:", sender, typeof(GameObject), true);

        }

        serializedObject.ApplyModifiedProperties();
    }
    #endif
}

}`

These are nowhere near fantastic or anything, and could use some improvements. They work though, and are available for some quick and dirty integration. Obviously, there are plenty more actions that could be made.

Honestly, I'm still toying with Wwise, so I'm not entirely certain how it all works, but thought I'd share in case others want to play.

Cheers

Comments

  • edited October 2022

    Welcome to the community, @laethyn.

    These are great, thanks for posting. I've posted them on the AC wiki here: https://adventure-creator.fandom.com/wiki/WWise_integration

  • I had also tested implementing it like this:
    though it involved modifying the core files. (directly selecting the Wwise event from the Dialogue -> Play Speech node without needing another node.)

    Yep, I realize it's a terrible idea, tthough I was just testing, and put all my changes behind a IsWwiseIntegrated script define. I'm also not going to publicly share my changes, as I don't want anyone else to think it's a good idea to change the core.

  • Just updated the wiki with a new action to change WWise RTPC int value game parameters. (for example, I have music playing during the splash screen. When the main menu loads, I send an rtpc call to reduce the volume of the music so it doesn't override my button hover/click sounds)

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

    if UNITY_EDITOR

    using UnityEditor;

    endif

    namespace AC {
    [System.Serializable]
    public class AK_SetRTPCIntParameter : Action {
    public override ActionCategory Category { get { return ActionCategory.Sound; } }
    public override string Title { get { return "Change RTPC value"; } }
    public override string Description { get { return "Change RTPC value."; } }

        [SerializeField] AK.Wwise.RTPC rtpcToSet;
        [SerializeField] float newValue;
    
        public override float Run() {
            rtpcToSet.SetValue(GameObject.Find("WwiseGlobal"), newValue);
            return 0f;
        }
    

    if UNITY_EDITOR

        public override void ShowGUI() {
            if (this == null) {
                return;
            }
    
            var serializedObject = new SerializedObject(this);
            serializedObject.Update();
            SerializedProperty rtpcEvent = serializedObject.FindProperty("rtpcToSet");
            EditorGUILayout.PropertyField(rtpcEvent, true);
    
            if (rtpcEvent != null) {
                newValue = EditorGUILayout.FloatField(newValue);
    
            }
            serializedObject.ApplyModifiedProperties();
        }
    

    endif

    }
    

    }`

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.