Forum rules - please read before posting.

Creating an action which triggers a parameter change in a FMOD event

Hello, I'm using Adventure Creator 1.62.6 (this project started years ago and since then I changed quite a lot of stuff so I'm kind of scared to update to the latest version) and I'm writing some actions to integrate FMOD into my game.

I have a problem with the action which triggers a parameter change in an event: whenever I set it (to let's say the one with ID == 3) and then I go back to it in the Action List editor, the currently selected parameter gets reverted to the first parameter found for the event (ID == 0).

Am I missing something trivial here?

Here's the relevant code used:

The action:

/*
*
*   Adventure Creator
*   by Chris Burton, 2013-2016
*   
*   "ActionTemplate.cs"
* 
*   This is a blank action template.
* 
*/

using UnityEngine;
using System.Collections;
using System.Linq;
using Assets.Domi.Scripts.Audio;
#if UNITY_EDITOR
using UnityEditor;

#endif

namespace AC
{
    [System.Serializable]
    public class DomiFmodSetParameterAction : Action
    {
        [SerializeField] private AudioEventDefinition audioEventDefinition;
        [SerializeField] private string parameter;
        [SerializeField] private float value;

        private int parameterIndex;

        //[SerializeField] private bool oneShot;

        public DomiFmodSetParameterAction()
        {
            this.isDisplayed = true;
            category = ActionCategory.Fmod;
            title = "Fmod Set Parameter";
            description = "";
        }


        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;
                return defaultPauseTime;
            }

            AudioManager.Instance.SetParameter(audioEventDefinition, parameter, value);

            isRunning = false;
            return 0f;
        }


        #if UNITY_EDITOR

        override public void ShowGUI()
        {
            if (audioEventDefinition != null && !audioEventDefinition.parameters.Any())
            {
                audioEventDefinition.GetEventParamenters();
            }

            // Action-specific Inspector GUI code here
            audioEventDefinition = EditorGUILayout.ObjectField("Audio event asset:", audioEventDefinition, typeof(AudioEventDefinition), false) as AudioEventDefinition;
            if (audioEventDefinition != null)
            {
                parameterIndex = EditorGUILayout.Popup("Paramenter: ", parameterIndex, audioEventDefinition.parameters.Select(x => x.name).ToArray());
                if (parameterIndex < audioEventDefinition.parameters.Count)
                    parameter = audioEventDefinition.parameters[parameterIndex].name;
            }

            value = EditorGUILayout.FloatField("Value: ", value);
            AfterRunningOption();
        }


        public override string SetLabel()
        {
            // Return a string used to describe the specific action's job.

            string labelAdd = "";
            return labelAdd;
        }

        #endif
    }
}

Audio Event Definition:

using System;
using System.Collections.Generic;
using FMOD.Studio;
using FMODUnity;
using UnityEngine;

namespace Assets.Domi.Scripts.Audio
{
    [CreateAssetMenu(menuName = "DoMI/Audio event")]
    public class AudioEventDefinition : ScriptableObject
    {
        [EventRef] [SerializeField] public string eventName;
        [SerializeField] public List<AudioEventParameter> parameters = new List<AudioEventParameter>();

        [SerializeField] public AudioEventType type;
        public enum AudioEventType
        {
            Music,
            Fx,
            FootStep,
            Ambience
        }

        public void GetEventParamenters()
        {
            parameters.Clear();

            var instance = RuntimeManager.CreateInstance(eventName);
            if (!instance.isValid())
                return;

            instance.getDescription(out EventDescription eventDescription);

            eventDescription.getParameterDescriptionCount(out int parameterDecriptionCount);

            for (int i = 0; i < parameterDecriptionCount; i++)
            {
                eventDescription.getParameterDescriptionByIndex(i, out PARAMETER_DESCRIPTION parameterDescription);
                parameters.Add(new AudioEventParameter(parameterDescription, this));
            }
        }
    }
}

Audio Event Parameter:

using FMOD.Studio;
using UnityEngine;

namespace Assets.Domi.Scripts.Audio
{
    public class AudioEventParameter
    {
        private PARAMETER_DESCRIPTION description;
        private AudioEventDefinition parent;


        public string name;
        public string type;
        private PARAMETER_ID id;
        [SerializeField] private float defaultValue;
        public float value;


        public AudioEventParameter(PARAMETER_DESCRIPTION description, AudioEventDefinition parent)
        {
            this.description = description;
            name = description.name;
            type = description.type.ToString();
            id = description.id;
            defaultValue = description.defaultvalue;
            this.parent = parent;
        }

        public void SetValue(float value)
        {
            this.value = value;
            AudioManager.Instance.SetParameter(parent, name, value);
        }

    }
}

Thanks in advance, I'm sure I'm missing something really simple but I'm having a hard time finding it!

Comments

  • Which variable in your custom Action specifically isn't being set correctly? The "parameter" string?

    Temporarily replace your ShowGUI's PopUp call to a simple TextField, i.e.:

    parameter = EditorGUILayout.TextField ("Parameter:", parameter);
    

    Does that then remain a fixed value? If so, it's probably not to do with the Action itself.

    Perhaps AudioEventParameter, or its variables, need to be serializable?

  • Perhaps AudioEventParameter, or its variables, need to be serializable?

    This was indeed the case! Thanks a lot :)

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.