I have some local parameters that are used on a number of different events (like normalised speed, for example), and I want to create functions that the designers can use to get and set parameter values on event instances without using strings.
Get/SetParameterByName() works fine, but if I’m updating a parameter at a high frequency I don’t want FMOD doing a string lookup multiple times per frame, so I figured I would use Get/SetParameterbyID() instead. However, using eventRef.Name always returns 0,0 as the parameter ID, so I looked through the forums and found an FMOD team member suggesting someone else use getParameterDescriptionByName(), then pulling the ID from the description, but this too only gave me 0,0 as the ID.
After scouring the documentation and forums and finding nothing on this, I finally discovered that if I pass in the EventInstance that I’m trying to get/set the parameter on, I can use eventInstance.getDescription() to access the EventInstance’s description, then [eventInstanceDescription].getParameterDescriptionByName() to access the Parameter’s description, then [parameterDescription].id to grab the ID and store it for using in the Get/SetParameterbyID() function.
Here’s some example code, since that explanation is kinda twisty:
private static PARAMETER_ID GetParamID(EventInstance instance, ParamRef parameter)
{
instance.getDescription(out EventDescription eventDesc);
eventDesc.getParameterDescriptionByName(parameter.Name, out PARAMETER_DESCRIPTION paramDesc);
return paramDesc.id;
}
Sorry if I have made any mistakes above, I am paraphrasing from my actual code which is split into a couple of functions across a couple of classes for reasons I won’t go into.
Anyway, that’s how I’ve solved it for now, hopefully this is useful to others. It does leave me with some questions though:
- If you’re not supposed to use Get/SetParameterByID() on local parameters, why is it a function in the EventInstance class?
- If you’re supposed to use Get/SetParameterByName() all the time, is it actually more efficient than it appears? And if so, why is that not in the documentation?
- I know there is an EditorParamRef in the Cache for each event that uses each parameter, but their IDs appear to be identical, so why can’t I access them from ParamRef.ID? Why return the default value instead?
I know multiple people who have had to solve this problem in various convoluted ways, so I think there should either be a more straightforward way to do it, documentation on how to do it as it is, or documentation explaining why to use Get/SetParameterByName() instead.