Event Lifecycle

Hi all,
i have some question about the lifecycle of an event. I’m using FMOD integrated in unity and i’m writing in C#.
1-I wanted to stop an event when it has finished playing. I don’t really understand how i can manage a sound that plays a sound in a loop. I want to command my event to “finish what you are playing and exit the loop”, but i can’t really figure out how i can do this.
2-I thought i should use the “getPlaybackState()” to debug and solve my problem, but when i print the playBackState of my event while playing i always get “STOPPED”. From what i’ve seen in documentation, “STOPPED” is when an event is not playng, but i can ear the sound of the event, and it’s why i really think i’m missing something.
The playback state is “STOPPED” also for an event that is playing a sound that is not looping.

My code is:

void Start ()
	eventInst = FMOD_StudioSystem.instance.GetEvent (asset);     
	eventInst.set3DAttributes (FMOD.Studio.UnityUtil.to3DAttributes (gameObject)); 
	eventInst.getPlaybackState (out s);

void Update(){


Anybody has any solution, suggestion or documentation to help me?


Firstly your code needs to call getPlaybackState every update to get the latest state.

If by looping you mean a loop-region on the logic track then the work flow would be:

  1. Add a parameter called trigger_finish_param to the event, leave the range at 0 to 1
  2. Change the loop-region so that it has a condition on the parameter from step 1, say only loop when the value is 0 to 0.5
  3. In unity call eventInst.setParameter(“trigger_finish_param”, 1.0f) followed by eventInst.release()

After you’ve done that the event will keep play until no instruments are active, then it will stop and clean itself up.

1 Like