# SetLoopPoints() of an Event?

**URL:** <https://qa.fmod.com/t/setlooppoints-of-an-event/13835>\
**Category:** Unity\
**Created:** [April 23, 2018, 5:56pm UTC](https://qa.fmod.com/t/setlooppoints-of-an-event/13835 "2018-04-23T17:56:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HappyOgre](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@HappyOgre](https://qa.fmod.com/u/HappyOgre)\
**Post date:** [April 23, 2018, 5:56pm UTC](https://qa.fmod.com/t/setlooppoints-of-an-event/13835/1 "2018-04-23T17:56:39Z")

</div>

I am trying to play an event and set the loop points of that event in Unity . I want to set it in Samples so I get an accurate loop.

Is there a way to get a reference to a sound from an event so I can call setLoopPoints()?

I have been trying this. The music plays but it doesn’t loop even once :

```
public uint startTime = 850036;
public uint endTime = 4229770;
[FMODUnity.EventRef]
public string musicFMOD;
FMOD.Studio.EventInstance musicEvent;
FMOD.Studio.EVENT_CALLBACK callback;
// Use this for initialization
void Start () {
    musicEvent = FMODUnity.RuntimeManager.CreateInstance(musicFMOD);
    callback = new FMOD.Studio.EVENT_CALLBACK(MusicCallback);
    musicEvent.setCallback(callback, FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED);
    musicEvent.start();
}

public FMOD.RESULT MusicCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance eventInstance, System.IntPtr parameters)
{
    if(type == FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED)
    {
        FMOD.ChannelGroup group;
        FMOD.Channel channel;
        FMOD.Sound sound;
        musicEvent.getChannelGroup(out group);

        group.getChannel(0, out channel);

        channel.getCurrentSound(out sound);
        channel.setLoopCount(-1);
        sound.setLoopPoints(startTime, FMOD.TIMEUNIT.PCM, endTime, FMOD.TIMEUNIT.PCM);
        sound.setLoopCount(-1);
    }

    return FMOD.RESULT.OK;
}
```

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [April 26, 2018, 5:01am UTC](https://qa.fmod.com/t/setlooppoints-of-an-event/13835/2 "2018-04-26T05:01:24Z")

</div>

> [@](#):
>
> I am trying to play an event and set the loop points of that event in Unity . I want to set it in Samples so I get an accurate loop.
> 
> Is there a way to get a reference to a sound from an event so I can call setLoopPoints()?
> 
> I have been trying this. The music plays but it doesn’t loop even once :
> 
> ```
> public uint startTime = 850036;
> public uint endTime = 4229770;
> [FMODUnity.EventRef]
> public string musicFMOD;
> FMOD.Studio.EventInstance musicEvent;
> FMOD.Studio.EVENT_CALLBACK callback;
> // Use this for initialization
> void Start () {
> musicEvent = FMODUnity.RuntimeManager.CreateInstance(musicFMOD);
> callback = new FMOD.Studio.EVENT_CALLBACK(MusicCallback);
> musicEvent.setCallback(callback, FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED);
> musicEvent.start();
> }
> 
> public FMOD.RESULT MusicCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance eventInstance, System.IntPtr parameters)
> {
> if(type == FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED)
> {
> FMOD.ChannelGroup group;
> FMOD.Channel channel;
> FMOD.Sound sound;
> musicEvent.getChannelGroup(out group);
> 
> group.getChannel(0, out channel);
> 
> channel.getCurrentSound(out sound);
> channel.setLoopCount(-1);
> sound.setLoopPoints(startTime, FMOD.TIMEUNIT.PCM, endTime, FMOD.TIMEUNIT.PCM);
> sound.setLoopCount(-1);
> }
> 
> return FMOD.RESULT.OK;
> }
> 
> ```

Can you confirm that all the API calls in the callback return Result.OK?
