# Max Instances and EventInstance creation

**URL:** <https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199>\
**Category:** Unity\
**Created:** [September 20, 2020, 10:36pm UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199 "2020-09-20T22:36:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crazymonkay](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@Crazymonkay](https://qa.fmod.com/u/Crazymonkay)\
**Post date:** [September 20, 2020, 10:36pm UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/1 "2020-09-20T22:36:42Z")

</div>

Hi all, FMOD novice here.

I was wondering how creating event instances with `FMODUnity.RuntimeManager.CreateInstance` handles Max Instances, in particular when the “Stealing” setting is set to None and the max number of instances has been reached.

Is there a way to tell that the max instances has been reached? In my code I am doing some additional work after creating the event instance, but if the event isn’t going to be played because it hit the max instances, I would like to abort since there isn’t any reason to do any more work.

Thanks!

---

<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:** [September 29, 2020, 1:13am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/2 "2020-09-29T01:13:34Z")

</div>

FMOD will dynamically make voices virtual or real depending on real time audibility, see the docs for info on [audibility calculation](https://fmod.com/resources/documentation-api?version=2.1&page=white-papers-virtual-voices.html#audibility-calculation).

> [@Crazymonkay](#):
>
> Is there a way to tell that the max instances has been reached? In my code I am doing some additional work after creating the event instance, but if the event isn’t going to be played because it hit the max instances, I would like to abort since there isn’t any reason to do any more work.

The events will still be played although they may just be virtual when they start, you can query [Studio::EventInstance::isVirtual](https://fmod.com/resources/documentation-api?version=2.1&page=studio-api-eventinstance.html#studio_eventinstance_isvirtual).

More information about the virtual voice system can be found in the docs:  
[https://fmod.com/resources/documentation-api?version=2.1&page=white-papers-virtual-voices.html#virtual-voice-system](https://fmod.com/resources/documentation-api?version=2.1&page=white-papers-virtual-voices.html#virtual-voice-system)

---

<div class="post-metadata">

**Author:** ![Crazymonkay](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@Crazymonkay](https://qa.fmod.com/u/Crazymonkay)\
**Post date:** [September 29, 2020, 1:45am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/3 "2020-09-29T01:45:12Z")

</div>

Thanks, the stealing concept is making more sense to me now.

I am still a little confused, though. For testing I set Max Instances to 1 and Stealing to None. I would expect that if I check isVirtual after creating each event instance, the 1st one would be false, and all others created after would be true until the 1st event instance finishes. However all of my event instances say that isVirtual is false.

---

<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:** [October 7, 2020, 3:57am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/4 "2020-10-07T03:57:09Z")

</div>

> [@Crazymonkay](#):
>
> all of my event instances say that isVirtual is false.

By this do you mean that they all always return this or each of them after creating them will return this?

---

<div class="post-metadata">

**Author:** ![Crazymonkay](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@Crazymonkay](https://qa.fmod.com/u/Crazymonkay)\
**Post date:** [October 8, 2020, 6:58pm UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/5 "2020-10-08T18:58:30Z")

</div>

So this is basically what my code is doing, playing one-shot audio on collision (I’ve removed a bunch of parts not related to FMOD):

```
private void OnCollisionEnter()
{
      fmodEventInstance = FMODUnity.RuntimeManager.CreateInstance("MyEvent");
      fmodEventInstance.start();

      bool isVirtual;
      fmodEventInstance.isVirtual(out isVirtual);
      Debug.Log(isVirtual);

      fmodEventInstance.clearHandle();
      fmodEventInstance.release();
}

```

If I have this attached to say 100 objects with the same settings I mentioned in my previous post, the sounds play correctly, only allowing 1 instance, but the Debug.Log will always say false. I’ve checked the result returned by isVirtual and there’s nothing wrong there.

---

<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:** [October 9, 2020, 1:26am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/6 "2020-10-09T01:26:41Z")

</div>

If you set the [stealing](https://www.fmod.com/resources/documentation-studio?version=2.1&page=event-macro-controls-reference.html#stealing) to ‘None’ then no new event instances can be played until the existing event instance stops, meaning that they aren’t virtual because they aren’t even playing.

---

<div class="post-metadata">

**Author:** ![Crazymonkay](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@Crazymonkay](https://qa.fmod.com/u/Crazymonkay)\
**Post date:** [October 9, 2020, 1:53am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/7 "2020-10-09T01:53:28Z")

</div>

Ok, so based on that I would think that [getPlaybackState](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#studio_eventinstance_getplaybackstate) could tell me whether or not the event instance actually started playing (regardless of whether or not it is virtual).

Testing it out, though, I always get a result of FMOD\_STUDIO\_PLAYBACK\_STARTING, so I guess I can’t immediately determine if the event will play or not?

---

<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:** [October 15, 2020, 5:24am UTC](https://qa.fmod.com/t/max-instances-and-eventinstance-creation/16199/8 "2020-10-15T05:24:57Z")

</div>

You could use [`StudioSystem::flushCommands`](https://fmod.com/resources/documentation-api?version=2.1&page=studio-api-system.html#studio_system_flushcommands) after starting the Event to force the system to update and process the Event, although this function does block the calling thread.
