StudioEventEmitter.SetParameter creates Garbage

Calling this function creates Garbage due to the internal code.

    public RESULT setParameterValue(string name, float value)
    {
        return FMOD_Studio_EventInstance_SetParameterValue(rawPtr, Encoding.UTF8.GetBytes(name + Char.MinValue), value);
    }

Is there an alternative way to set the parameter, i.e. by caching the parameter instance. The API seems to have hidden the instances pretty well for some reason. Is there another API that I should be using for this?

Is there an example somewhere of parameter being set every frame in Unity?

You are able get and store a reference to a parameter using: FMOD.Studio.ParameterInstance

FMOD.Studio.EventInstance event;
FMOD.Studio.ParameterInstance param;

event.getParameter("paramName", out param);

param.setValue(floatValue);

So the solution is just not to use the StudioEventEmitter?

If you are worried about excess garbage then it’s probably a better idea to create your own class for playing sounds and getting/setting parameters.
StudioEventEmitter can still be used as a guide.

Thank you. Anyone developing games in unity would(should be) concerned about per frame garbage. It is a core issue with developing games in managed languages. There are some easy things you could do to fix this.

Here is the dirt simplest way. Just install a cache between the parameters

public static class FmodFix
{
private static Dictionary<string, byte[]> StringTable = new Dictionary<string, byte[]>();
public static byte[] Encode(string name)
{
byte[] results;
if (!StringTable.TryGetValue(name, out results))
{
results = Encoding.UTF8.GetBytes(name + Char.MinValue);
StringTable[name] = results;
}
return results;
}

}

    public RESULT setParameterValue(string name, float value)
    {
        return FMOD_Studio_EventInstance_SetParameterValue(rawPtr, FmodFix.Encode(name), value);
    }