# C# - Failing to load samples

**URL:** <https://qa.fmod.com/t/c-failing-to-load-samples/15429>\
**Category:** FMOD Engine\
**Created:** [February 2, 2020, 1:51pm UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429 "2020-02-02T13:51:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![domj](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@domj](https://qa.fmod.com/u/domj)\
**Post date:** [February 2, 2020, 1:51pm UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429/1 "2020-02-02T13:51:13Z")

</div>

Hi,

I’m trying to wrap my head around the Studio API to eventually integrate it into my application.

I have successfuly played back a wave file using the Core API, along with some basic FFT analysis.

I’m now stuck at playing back FMOD Studio events. I am following the steps from the documentation:

1. Init the Studio System \> OK
2. Load Bank (incl. strings) \> OK
3. Explicitly load samples \> Forever in LOADING state, but can be skipped
4. Lookup Event via path and create an instance from the EventDescription \> OK
5. Call Start on the instance \> OK, but now the instance is forever stuck in the STARTING state as it fails to load the sample and never plays

Using system.flushSampleLoading() after sample load calls does not block (strange) and neither fixes anything.

The Studio project is compiled for Desktop and functions fully in Unity.

I’m using the \*.cs wrappers and dlls included in the API installation.

Is there anything I’m missing in the setup process or anywhere else? Any help is much appreciated, thanks!

Here’s the test app source and build incl. the FMOD Studio project

> **[This transfer expired](https://www.dropbox.com/transfer/AAAAAMvFotqdgiJ6c1peS2cAXRpAx6SPgt70E_wfqNtAaoT5UoRdrBk)**
>
> Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!

---

<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:** [February 13, 2020, 3:58am UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429/2 "2020-02-13T03:58:30Z")

</div>

Are you able to check the FMOD\_RESULT returned from all the FMOD functions, it may shed some light on any issues.

---

<div class="post-metadata">

**Author:** ![domj](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@domj](https://qa.fmod.com/u/domj)\
**Post date:** [February 13, 2020, 6:42pm UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429/3 "2020-02-13T18:42:33Z")

</div>

Yes, I have wrapped every FMOD function with a check function that stops the program (and reports the output) unless the result is OK. And (unfortunately), all FMOD functions return with OK so the program runs fine - but never loads the samples.

```
static void emitStudioEventExample()
{
    var system = initStudioSystem();

    Console.WriteLine("Loading banks");

    FMOD.Studio.Bank bank;
    checkResult(system.loadBankFile("bank/Build/Desktop/Master.bank", FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank));
    FMOD.Studio.Bank stringsBank;
    checkResult(system.loadBankFile("bank/Build/Desktop/Master.strings.bank", FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out stringsBank)); // Must be loaded for Event paths to work

    FMOD.Studio.LOADING_STATE lState = FMOD.Studio.LOADING_STATE.ERROR;

    Console.WriteLine("Loading sample data");
    checkResult(bank.loadSampleData());

    do
    {
        checkResult(bank.getSampleLoadingState(out lState));
        Console.WriteLine(lState.ToString());
        System.Threading.Thread.Sleep(500);
    }
    while (lState != FMOD.Studio.LOADING_STATE.LOADED);

    checkResult(system.flushSampleLoading());

    FMOD.Studio.EventDescription[] evList;
    bank.getEventList(out evList);

    foreach (var evv in evList)
    {
        string path;
        evv.getPath(out path);
        Console.WriteLine(path);

        Guid guid;
        evv.getID(out guid);
        Console.WriteLine(guid);
    }

    Console.WriteLine("Getting event");

    FMOD.Studio.EventDescription ev;
    checkResult(system.getEvent("event:/Event", out ev));

    checkResult(ev.loadSampleData());

    do
    {
        // Gets stuck here with "LOADING"
        checkResult(ev.getSampleLoadingState(out lState));
        Console.WriteLine(lState);
        System.Threading.Thread.Sleep(500);
    }
    while (lState != FMOD.Studio.LOADING_STATE.LOADED);

    Console.WriteLine("Creating new event instance");

    FMOD.Studio.EventInstance instance;
    checkResult(ev.createInstance(out instance));
    checkResult(instance.start());

    while (true) {
        FMOD.Studio.PLAYBACK_STATE pState;
        instance.getPlaybackState(out pState);
        Console.WriteLine(pState);

        System.Threading.Thread.Sleep(500);

    };
}
```

---

<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:** [February 20, 2020, 11:43pm UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429/4 "2020-02-20T23:43:02Z")

</div>

It looks like you need to add `system.update()` to each of your while loops.

> …calling [Studio::System::update](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-system.html#studio_system_update) from your game is a fast operation which submits the queued command buffer to the asynchronous thread and performs any asynchronous callbacks due to processing on the Studio update thread.

[https://fmod.com/resources/documentation-api?version=2.0&page=studio-guide.html#studio-system-processing](https://fmod.com/resources/documentation-api?version=2.0&page=studio-guide.html#studio-system-processing)

---

<div class="post-metadata">

**Author:** ![domj](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@domj](https://qa.fmod.com/u/domj)\
**Post date:** [February 21, 2020, 10:33am UTC](https://qa.fmod.com/t/c-failing-to-load-samples/15429/5 "2020-02-21T10:33:49Z")

</div>

Thank you very much @cameron-fmod !  
Missing that call was indeed the issue.
