Set Parameter from animation

Good day!

I want to change parameter value inside an AnimationEvent. My logic is “when AnimationEvent triggered - set this parameter value”.

I made a code logic but it doesn’t work. Can you explain what is my fault?

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

public class FmodAnimationGlobalParameter : MonoBehaviour
{
private readonly Dictionary<string, PARAMETER_ID> _paramCache = new();

public void SetGlobalParameter(string parameterName, float value)
{
    if (!_paramCache.TryGetValue(parameterName, out var paramId))
    {
        RuntimeManager.StudioSystem.getParameterDescriptionByName(
            parameterName,
            out var desc
        );

        paramId = desc.id;
        _paramCache.Add(parameterName, paramId);
    }

    RuntimeManager.StudioSystem.setParameterByID(paramId, value);
}

}

Hi,

Thank you for sharing the code.

Could you please elaborate a bit more on how the code logic is not working?

If the issue is that you cannot find the method in the Animation Event function list, it is likely because Unity AnimationEvents can only call methods with zero or one parameter, while your SetGlobalParameter(string parameterName, float value) method takes two parameters.