# Stuck on "Reloading domain" when the preferences are set to recompile after finished playing

**URL:** https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861
**Category:** Unity
**Created:** [February 12, 2023, 6:14pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861 "2023-02-12T18:14:39Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Francoimora](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Francoimora](https://qa.fmod.com/u/Francoimora)
#### Post date: [February 12, 2023, 6:14pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/1 "2023-02-12T18:14:39Z")

</div>

Hi,

We recently installed the Hot Reload plugin for Unity ([Download | Hot Reload for Unity](https://hotreload.net/download)) which made us change our preferences settings to “Recompile After Finished Playing”. The problem is that when we exit the play mode, Unity tries to recompile and fails to do it because of FMOD. The window “Reloading domain” can’t disappear and we have to kill Unity process. Here is the editor.log part that explain the problem :

```auto
Reloading assemblies after forced synchronous recompile.
Begin MonoManager ReloadAssembly
Thread 0x381d87000 may have been prematurely finalized
UnityException: Load can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
  at (wrapper managed-to-native) UnityEngine.ResourcesAPIInternal.Load(string,System.Type)
  at UnityEngine.ResourcesAPI.Load (System.String path, System.Type systemTypeInstance) [0x00000] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:71 
  at UnityEngine.Resources.Load (System.String path, System.Type systemTypeInstance) [0x00001] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:122 
  at UnityEngine.Resources.Load (System.String path) [0x00001] in /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:112 
  at FMODUnity.Settings.Initialize () [0x0001a] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/Settings.cs:267 
  at FMODUnity.Settings.get_Instance () [0x0000f] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/Settings.cs:255 
  at FMODUnity.RuntimeUtils.DebugLogError (System.String message) [0x00001] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/RuntimeUtils.cs:572 
  at FMODUnity.RuntimeManager.DEBUG_CALLBACK (FMOD.DEBUG_FLAGS flags, System.IntPtr filePtr, System.Int32 line, System.IntPtr funcPtr, System.IntPtr messagePtr) [0x00023] in /Users/francois/Projects/Arckhania/Assets/Plugins/FMOD/src/RuntimeManager.cs:77 
  at (wrapper native-to-managed) FMODUnity.RuntimeManager.DEBUG_CALLBACK(FMOD.DEBUG_FLAGS,intptr,int,intptr,intptr)
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnhandledExceptionHandler.bindings.cs:46)
UnityEngine.ResourcesAPIInternal:Load(String, Type)
UnityEngine.ResourcesAPI:Load(String, Type) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:71)
UnityEngine.Resources:Load(String, Type) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:122)
UnityEngine.Resources:Load(String) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Resources/Resources.bindings.cs:112)
FMODUnity.Settings:Initialize() (at Assets/Plugins/FMOD/src/Settings.cs:267)
FMODUnity.Settings:get_Instance() (at Assets/Plugins/FMOD/src/Settings.cs:255)
FMODUnity.RuntimeUtils:DebugLogError(String) (at Assets/Plugins/FMOD/src/RuntimeUtils.cs:572)
FMODUnity.RuntimeManager:DEBUG_CALLBACK(DEBUG_FLAGS, IntPtr, Int32, IntPtr, IntPtr) (at Assets/Plugins/FMOD/src/RuntimeManager.cs:77)

(Filename: Assets/Plugins/FMOD/src/Settings.cs Line: 267)

```

Notes :

- Macbook Pro M1 Max 16"
- Unity 2022.2.5f1 (silicon build)
- FMOD 2.02.11 (tested with 2.02.09 too)

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [February 13, 2023, 6:16am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/2 "2023-02-13T06:16:24Z")

</div>

Hi,

Changing a reference and trying to trigger a `OneShot` I was not able to reproduce the issue.

Were there any particular changes you were making when it was getting stuck? Or is it every time you try and end play mode?

Would it be possible to get a stripped-out version of the Unity project that is experiencing the issue uploaded to your [Profile](https://fmod.com/profile#uploads)?

---

<div class="post-metadata">

### Author: ![Francoimora](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Francoimora](https://qa.fmod.com/u/Francoimora)
#### Post date: [February 13, 2023, 8:11am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/3 "2023-02-13T08:11:11Z")

</div>

It happens everytime I exit play mode. If I comment the line that is causing this problem in the Settings.cs , Fmod doesn’t work but the game can exit play mode properly. Did you try it with an Apple Silicon build ? Maybe it’s only related to this specific version, I don’t know.

It would be really hard for us to send the project right now.

---

<div class="post-metadata">

### Author: ![Francoimora](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Francoimora](https://qa.fmod.com/u/Francoimora)
#### Post date: [February 16, 2023, 8:18am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/4 "2023-02-16T08:18:03Z")

</div>

Do you have an update on this ? We can try to build an empty repro project if needed.

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [February 17, 2023, 1:09am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/5 "2023-02-17T01:09:17Z")

</div>

Hi,

Apologies for the delayed response. That would be extremely useful, you can either upload the project to your [Profile](https://fmod.com/profile#uploads) or DM me directly.

---

<div class="post-metadata">

### Author: ![wishfully](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/wishfully/32/6716_2.png) [@wishfully](https://qa.fmod.com/u/wishfully)
#### Post date: [April 10, 2024, 1:32pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/6 "2024-04-10T13:32:12Z")

</div>

Same thing for us.

Unity 2023.1.19  
FMOD 2.02.19

After exiting playmode we sometime get stuck on “reloading domain”.  
Same error in Editor log as the post starter.

I have had to force quit Unity 5 times today.

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [April 11, 2024, 1:51am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/7 "2024-04-11T01:51:08Z")

</div>

Hi,

This can be caused if you interact with the Core FMOD system and objects aren’t being released correctly. Was there a recent change made that introduced the issue?

---

<div class="post-metadata">

### Author: ![JustinSnowman](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@JustinSnowman](https://qa.fmod.com/u/JustinSnowman)
#### Post date: [April 17, 2024, 7:00pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/8 "2024-04-17T19:00:47Z")

</div>

Hey,

I’m having the same issue where Unity gets stuck reloading scripts / domain.

In my code, I have an event with a beat callback. When I exit play mode, the music keeps playing and Unity freezes when I try and reload.  
It looks like FMOD is throwing an Exception when trying to release the event due to the instance receiving the callback becoming null?

```auto
NullReferenceException: Object reference not set to an instance of an object
Surfside.UI.RadioController.HandleMusicBeat (FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr eventInstance, System.IntPtr parameters) (at Assets/Scripts/UI/RadioController.cs:138)
FMOD.Studio.System.release () (at Assets/Plugins/FMOD/src/fmod_studio.cs:423)
FMODUnity.RuntimeManager.ReleaseStudioSystem () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:266)
FMODUnity.RuntimeManager.OnDestroy () (at Assets/Plugins/FMOD/src/RuntimeManager.cs:723)

```

The line of code that is pointed to in the top of the stack trace is this:

```auto
if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT && radioImage != null)

```

I do not get this issue when I don’t call setCallBack() on my EventInstance. Calling release() on it in OnDestroy doesn’t seem to help either.

I’m on Uinty 2022.3.12 & FMOD 2.02.21

Edit: When the game starts, I create an event instance, set the callback, and play. When I exit play mode, I call stop and release on the event instance.

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [April 18, 2024, 4:55am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/9 "2024-04-18T04:55:37Z")

</div>

Hi,  
Would it be possible to see more of the code? What operating system are you on? Could I get a screenshot of the event in your FMOD project?

---

<div class="post-metadata">

### Author: ![JustinSnowman](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@JustinSnowman](https://qa.fmod.com/u/JustinSnowman)
#### Post date: [April 18, 2024, 5:05pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/10 "2024-04-18T17:05:28Z")

</div>

Hey, yeah! Yesterday I was in the office on my Mac, and the issue was as described. Trying it out at home on my Windows desktop, the music continues for a short time after exiting play mode and then Unity actually just crashes.

```auto
private void Start()
{
    var eventDesc = RuntimeManager.GetEventDescription(eventReference.Guid);
    var instance = eventDesc.createInstance(out EventInstance newInstance);
    beatCallback = new EVENT_CALLBACK(HandleMusicBeat);
    instance.setCallback(beatCallback, EVENT_CALLBACK_TYPE.TIMELINE_BEAT);

    instance.start();
}

private void OnDestroy()
{
    currentMusicInstsance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
    currentMusicInstsance.release();
}

private RESULT HandleMusicBeat(EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)
 {
        if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT && radioImage != null)
        {
            radioImage.transform.DOPunchScale(new Vector3(0.05f, 0.05f, 0), 0.2f, 10, 0).SetUpdate(true);  
        }
        return RESULT.OK;
}

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/aa15f63ba4b653457f42d9592d00f7f67990f8fd.png)

Edit:  
Here’s the stacktrace the crash gave me:

```auto
=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at FMOD.Studio.System:FMOD_Studio_System_Release <0x00089>
	  at FMOD.Studio.System:release <0x00022>
	  at FMODUnity.RuntimeManager:ReleaseStudioSystem <0x0005a>
	  at FMODUnity.RuntimeManager:OnDestroy <0x00042>
	  at System.Object:runtime_invoke_void __this__ <0x00087>
	  at <unknown> <0xffffffff>
	  at UnityEngine.Object:DestroyImmediate <0x00094>
	  at UnityEngine.Object:DestroyImmediate <0x00022>
	  at FMODUnity.RuntimeManager:Destroy <0x0005a>
	  at FMODUnity.RuntimeManager:HandlePlayModeStateChange <0x0007a>
	  at UnityEditor.EditorApplication:Internal_PlayModeStateChanged <0x000aa>
	  at <Module>:runtime_invoke_void_int <0x0008a>
=================================================================

```

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [April 19, 2024, 5:09am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/11 "2024-04-19T05:09:19Z")

</div>

Thank you for the code.

We have a scripting example outlining creating a `BeatEventCallback` here: [Unity Integration | Scripting Examples - Timeline Callbacks](https://fmod.com/docs/2.02/unity/examples-timeline-callbacks.html). Would it be possible to compare against this as it may provide a solution?

Hope this helps

---

<div class="post-metadata">

### Author: ![JustinSnowman](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@JustinSnowman](https://qa.fmod.com/u/JustinSnowman)
#### Post date: [April 19, 2024, 1:19pm UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/12 "2024-04-19T13:19:28Z")

</div>

Thank you for sending this example! I must have missed in in my searching.

I have solved the crash issue on my Windows machine by **making the HandleMusicBeat callback method static**. The method signature is as follows: `private static RESULT HandleMusicBeat(EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)`

I assume the issue is also solved on Mac, but I won’t be in the office for a few days so I won’t know till then.

---

<div class="post-metadata">

### Author: ![wishfully](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/wishfully/32/6716_2.png) [@wishfully](https://qa.fmod.com/u/wishfully)
#### Post date: [May 20, 2024, 9:12am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/13 "2024-05-20T09:12:11Z")

</div>

Any news on this issue?

Everything works as expected as long as we don’t change any scripts while in play mode. If we do that, forcing Unity to recompile after exiting playmode, we need to force quit Unity every time.

Recompile after finished playing is the preferred setting for our team and this has not been a problem in previous versions of FMOD.

(Same issue if “reload domain” checkbox is checked)

- Unity 2023.1.19
- FMOD 2.02.19

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/9e9f53b2d59222a6ec4eb46b2075dbfd92086781.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/3/396b954d1d75ab5200aba8387285209d6be176d2.png)

---

<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: [May 21, 2024, 4:41am UTC](https://qa.fmod.com/t/stuck-on-reloading-domain-when-the-preferences-are-set-to-recompile-after-finished-playing/19861/14 "2024-05-21T04:41:31Z")

</div>

There was another issue causing this that was fixed in version [2.02.21](https://www.fmod.com/docs/2.02/api/welcome-revision-history.html):

> - Unity - Fixed editor hang when live recompiling code.
