Replace Event While Playing

Bit new to FMOD and I have a basic question. I have an established event emitter called “FootstepPlayer”. It has an event, “DefaultFootstep”, that plays when a character walks.

I have set up a trigger where I want to replace the event inside the eventemitter to “MetalFootstep”, but so far no luck.

public StudioEventEmitter FootstepPlayer;
public EventReference MetalFootstep;

public void OnTriggerEnter(Collider other){
FootstepPlayer.Event = MetalFootstep;

}

^Something along those lines. How do I do this?

StudioEventEmitter is designed to only handle a single event - as a result, if you don’t want to handle the lifetime of the event instance yourself, what you want will require you to make some sort of modification to the script.

As a basic example, the following function can be added to StudioEventEmitter, and will stop the currently playing instance and set the emitter to play your event of choice:

public void ChangeEvent(EventReference eventRef)
{
    Stop();
    EventReference = eventRef;
    Lookup();
}

You then do the following in your own script to set the emitter to use the MetalFootstep event when it enters the trigger:

public void OnTriggerEnter(Collider other)
{
    FootstepPlayer.ChangeEvent(MetalFootstep);
}