Skip to content

Infinite hang when reloading a scene contains a manually spawned NetworkObject with a SpriteLibrary and a SpriteResolver #4095

Closed

Description

@acavailhez

Description

Infinite hang when reloading a scene contains a manually spawned NetworkObject with a SpriteLibrary and a SpriteResolver

Reproduce Steps

  1. Create an empty scene
  2. Add a NetworkManager, with UnityTransport
  3. Create a new prefab with NetworkObject, SpriteRenderer, Animator, SpriteLibrary, SpriteResolver (following basically this tutorial: https://www.youtube.com/watch?v=4xPHqEEa-V0)
  4. Create an empty object TestCrash with the following code, and link the prefab from (3) in the inspector
public class TestCrash : NetworkBehaviour
{
    [SerializeField] public GameObject prefab = null!;
    private bool _alreadyCalled;

    private void Start()
    {
        var networkManager = NetworkManager.Singleton;
        var unityTransport = networkManager.GetComponent<UnityTransport>();

        // Start local server
        unityTransport.UseWebSockets = false; // if applicable
        unityTransport.SetConnectionData("0.0.0.0", 7777);
        networkManager!.NetworkConfig.NetworkTransport = unityTransport;
        networkManager.StartHost();

        NetworkManager.Singleton.SpawnManager.InstantiateAndSpawn(
            prefab!.GetComponent<NetworkObject>(),
            OwnerClientId,
            destroyWithScene: true,
            position: Vector3.zero
        );
    }

    private void Update()
    {
        if (_alreadyCalled) return;
        if (Time.timeSinceLevelLoad < 3f) return;
        _alreadyCalled = true;
       NetworkManager.Singleton.SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    }
}

TestCrash is some code that

  • starts a local server
  • spawns the prefab
  • waits 3 seconds
  • reloads the scene

Actual Outcome

After a few attempts, the scene never reloads and the Unity editor hangs forever (has to be force quitted)

Expected Outcome

The scene reloads every 3s

Environment

  • OS: Windows 11
  • Unity Version: 6000.4.7f1
  • Netcode Version: 2.12.0

Additional Context

  • This bug did not happen with 2.12.0 and Unity 6000.3.11f1 (started happening after upgrading to 6000.4.7f1)
  • The bug doesn't happen without destroyWithScene: true,
  • Removing the SpriteResolver/SpriteLibrary stops the bug from happening
  • The NetworkObject must be spawned with InstantiateAndSpawn, if the prefab is added to the scene, the bug doesn't happen

Here is a dump of the Main Thread stack when the editor is hanging. The CPU is at 0% at that point. Maybe a lock contention?

<unknown> 0x00007ff973d63cb4
<unknown> 0x00007ff973c30543
<unknown> 0x00007ff97107e558
UnityClassic::Baselib_SystemFutex_Wait(int * __ptr64,int,unsigned int) 0x00007ff8886af7f6
ProfilerMutexLock(Mutex & __ptr64,char const * __ptr64,profiling::Marker & __ptr64,char const * __ptr64,int) 0x00007ff88b1a4450
PersistentManager::Lock(PersistentManager::LockFlags,profiling::Marker * __ptr64) __ptr64 0x00007ff88b1a1b83
PersistentManager::GetPathName(EntityId) __ptr64 0x00007ff88b1968bb
GetGUIDFromEntityId(EntityId) 0x00007ff888e786fe
AssetChangedNotifier::UnsubscribeFromAll(EntityId) __ptr64 0x00007ff88a209aee
SpriteRenderer::MainThreadCleanup(void) __ptr64 0x00007ff88b631e42
delete_object_internal_step1(Object * __ptr64) 0x00007ff88b8cd380
CommitBatchDelete(BatchDelete & __ptr64) 0x00007ff88b5286d2
DestroyObjectHighLevel_Internal(Object * __ptr64,bool) 0x00007ff88b532e31
DestroyObjectHighLevel(Object * __ptr64,bool) 0x00007ff88b532ba8
DelayedDestroyCallback(Object * __ptr64,void * __ptr64) 0x00007ff88b7963cb
DelayedCallManager::Update(int) __ptr64 0x00007ff88b797ac8
<unknown> 0x00007ff88b4f9d6b
ExecutePlayerLoop(NativePlayerLoopSystem * __ptr64) 0x00007ff88b517f5b
ExecutePlayerLoop(NativePlayerLoopSystem * __ptr64) 0x00007ff88b51811a
PlayerLoop(void) 0x00007ff88b51d105
EditorPlayerLoop::Execute(void) __ptr64 0x00007ff889ab957a
PlayerLoopController::InternalUpdateScene(bool,bool) __ptr64 0x00007ff889ab2a9c
PlayerLoopController::UpdateSceneIfNeededFromMainLoop(void) __ptr64 0x00007ff889ab4dad
Application::TickTimer(void) __ptr64 0x00007ff889acc4c3
<unknown> 0x00007ff8894bfb2c
UnityMain 0x00007ff8894c8693
<unknown> 0x00007ff6ae972f2a
<unknown> 0x00007ff97360e957
<unknown> 0x00007ff973caad6c

Activity

  1. acavailhez commented on Jul 23, 2026

    @acavailhez
    Author

    Hello @NoelStephensUnity !

    Thanks a lot for the package! It's very useful.
    I've installed it and changed DestroyInstanceWithScene to true in the editor, and the editor does crash at the second reload of the scene

    (this doesn't affect a build by the way, just the editor)

  2. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Jul 23, 2026
  3. EmandM commented on Aug 7, 2026

    @EmandM
    Member

    That crash is expected behaviour. If the instance is destroyed in the scene reload, then unexpected behaviour will occur.

  4. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 7, 2026
  5. acavailhez commented on Aug 11, 2026

    @acavailhez
    Author

    Hi @EmandM!

    I'm not sure I understand your answer, you're saying that with the setup:

    • InstantiateAndSpawn a NetworkObject with destroyWithScene: false
    • Change the sprite
    • Reload the scene

    It is expected that the Unity editor might hang forever?

    Are you able to reproduce the issue? (it could be some specific conditions on my machine)

  6. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Aug 11, 2026
  7. EmandM commented on Aug 11, 2026

    @EmandM
    Member

    Ah, I think I understand. Just to clarify, your core issue is that the Unity Editor is hanging, not that your Netcode logic isn't working? You're right that it's not expected that the Unity editor hangs forever in this case. We've not been able to reproduce the engine hang on our end.

    This github repo is for specifically Netcode for GameObjects issues. Seeing as this editor hang crosses a few product boundaries it's going to be easiest for us to address if you can report a bug in the editor. Feel free to link your case number here and we can follow up on your report to ensure it gets to the right place.

  8. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 11, 2026
  9. NoelStephensUnity commented on Aug 12, 2026

    @NoelStephensUnity
    Member

    @acavailhez
    I did replicate the issue and tried several combinations to resolve the issue. (Using 6000.4.0f1)
    It does appear (oddly enough) that only if you replace the sprite and mark the instance to not destroy with the scene load (single mode) then (on my side using Windows 11) it ends up freezing the editor (attaching with a debugger isn't very useful either under this scenario as well).

    However, if I comment out the code that swaps the sprite, then it runs perfectly fine. (🔥)

    As @EmandM mentioned, this does seem like an editor specific issue that you can file as an editor related bug report via the editor.

    However, we understand the pain associated with not being able to achieve something that does seem simple but ends up being an edge case issue. When using LoadSceneMode.Single, it places a lot of the control over to the SceneManager for things like when a scene is fully unloaded (and the assets within the scene) which could potentially expose a bug under very specific timing related circumstances.

    Typically, I recommend using an additive scene loading flow. This provides you with a bit more control over when you want to unload or load a scene and you can change the timing for both based on your project's needs.

    As such, here is an example project that accomplishes the same thing you were trying to do using LoadSeneMode.Single but it uses the additive scene loading pattern:

    GH-4095-Solution.zip

    Below is a video of the project running and shows you can switch the mode (destroy with scene or don't destroy with scene) on the fly in playmode and it continues to work whether destroying or not destroying when the scene it is currently within is unloaded (and it replaces the sprite on the newly instantiated and spawned instance):

    GH-4095-Solution.mov

    Let me know if this approach works for you (at least until the current issue when using SingleMode scene loading is resolved)?

  10. acavailhez commented on Aug 18, 2026

    @acavailhez
    Author

    Hi @NoelStephensUnity !

    Thanks a lot for your time and effort!

    I think additive scene loading is not going to work for what I'm doing, but I appreciate the idea.

    The lock contention only happens in the editor so I have a workaround for now. I'd to remove it one day!

  11. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Aug 18, 2026
  12. NoelStephensUnity commented on Sep 25, 2026

    @NoelStephensUnity
    Member

    @acavailhez
    This has been identified as an engine issue and should be resolved (currently) in the following editor versions:
    6000.3.24f1, 6000.5.3f1 and 6000.6.

    No 6000.4 released build has this fix in it (you reported you were using 6000.4.7f1, which means the bug still exists on this version of Unity).

    My recommendation would be to update to 6000.5.3f1 or higher to resolve the underlying issue.

    Let me know if this (finally) resolves your issue?

  13. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Sep 25, 2026
  14. michalChrobot commented on Sep 25, 2026

    @michalChrobot
    Member

    To add to that 6000.4 and 6000.5 are out of support already and won't receive further updates so preferably you would move to 6000.6 (although latest 6000.5 should also resolve your issue, just remember that the editor itself won't get further updates)

    With that I will close the issue but we can always reopen if this won't fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:supportQuestions or other support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions