Hello,
We have to use event emitters for our footstep system and I’m just checking there’s a way to get an event emitters parameter ID once instead of getting it every time it’s played, before we were creating instances inside the script and getting the ID once which was fine but with the emitter the cached ID isn’t setting the parameter every time. I can set it by name fine but in the interest of performance I’d like to set by ID.
I’m grabbing the ID’s like this in Awake
m_LeftFootSurfaceParamID = FMODUtility.GetLocalParameterID(m_LeftFootstepEmitter.EventInstance, "SurfaceType");
m_RightFootSurfaceParamID = FMODUtility.GetLocalParameterID(m_RightFootstepEmitter.EventInstance, "SurfaceType");
Here’s the utility function
public static PARAMETER_ID GetLocalParameterID(EventInstance eventInstance, string parameterName) {
eventInstance.getDescription(out EventDescription description);
description.getParameterDescriptionByName(parameterName, out PARAMETER_DESCRIPTION parameterDescription);
return parameterDescription.id;
}
And here we’re trying to set the parameter when a footstep event plays
void PlayFootstepSound(int footIndex) {
ObjectSurfaceType surfaceType = ObjectSurfaceType.None;
if (Physics.Raycast(transform.position + m_RaycastOffset, Vector3.down, out RaycastHit hitInfo)) {
surfaceType = hitInfo.GetSurfaceType();
}
switch (footIndex) {
case 0:
m_LeftFootstepEmitter.Play();
m_LeftFootstepEmitter.SetParameter(m_LeftFootSurfaceParamID, (int)surfaceType);
break;
case 1:
m_RightFootstepEmitter.Play();
m_RightFootstepEmitter.SetParameter(m_RightFootSurfaceParamID, (int)surfaceType);
break;
}
}
I should also add we’re adding the event emitters in awake too
m_LeftFootstepEmitter = m_Animator.GetBoneTransform(HumanBodyBones.LeftFoot).gameObject.AddComponent<StudioEventEmitter>();
m_RightFootstepEmitter = m_Animator.GetBoneTransform(HumanBodyBones.RightFoot).gameObject.AddComponent<StudioEventEmitter>();
m_LeftFootstepEmitter.EventReference = RuntimeManager.PathToEventReference("event:/Character/Footstep");
m_RightFootstepEmitter.EventReference = RuntimeManager.PathToEventReference("event:/Character/Footstep");
Is there no way to initialise the instance straight away OnEnable or similar so I can grab any event information?
Also I’d have thought we should set the parameter before playing but in testing by name it was only working afterwards.
Thanks for your time