# Event Lifecycle

**URL:** https://qa.fmod.com/t/event-lifecycle/12118
**Category:** Unity
**Created:** [October 27, 2015, 3:04pm UTC](https://qa.fmod.com/t/event-lifecycle/12118 "2015-10-27T15:04:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Pelle](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/pelle/32/79_2.png) [@Pelle](https://qa.fmod.com/u/Pelle)
#### Post date: [October 27, 2015, 3:04pm UTC](https://qa.fmod.com/t/event-lifecycle/12118/1 "2015-10-27T15:04:40Z")

</div>

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);
    eventInst.start();
}

void Update(){
    Debug.Log(s);

}

```

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

Thanks,  
Simone

---

<div class="post-metadata">

### Author: ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)
#### Post date: [October 27, 2015, 11:45pm UTC](https://qa.fmod.com/t/event-lifecycle/12118/2 "2015-10-27T23:45:41Z")

</div>

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.
