Answered
0
0

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 must to post comments
Best Answer
-1
0

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);
  • Thomas

    So the solution is just not to use the StudioEventEmitter?

  • Cameron Baron

    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.

  • Thomas

    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.

  • Thomas

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

    public static class FmodFix
    {
    private static Dictionary StringTable = new Dictionary();
    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);
    }

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.