Repository navigation
Closed
Labels
type:supportQuestions or other supportQuestions or other support
Description
Description
Infinite hang when reloading a scene contains a manually spawned NetworkObject with a SpriteLibrary and a SpriteResolver
Reproduce Steps
- Create an empty scene
- Add a NetworkManager, with UnityTransport
- Create a new prefab with NetworkObject, SpriteRenderer, Animator, SpriteLibrary, SpriteResolver (following basically this tutorial: https://www.youtube.com/watch?v=4xPHqEEa-V0)
- Create an empty object
TestCrashwith 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
Metadata
Metadata
Assignees
Labels
type:supportQuestions or other supportQuestions or other support
Activity
acavailhez commentedon Jul 23, 2026
Hello @NoelStephensUnity !
Thanks a lot for the package! It's very useful.
I've installed it and changed
DestroyInstanceWithScenetotruein 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)
EmandM commentedon Aug 7, 2026
That crash is expected behaviour. If the instance is destroyed in the scene reload, then unexpected behaviour will occur.
acavailhez commentedon Aug 11, 2026
Hi @EmandM!
I'm not sure I understand your answer, you're saying that with the setup:
InstantiateAndSpawna NetworkObject withdestroyWithScene: falseIt 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)
EmandM commentedon Aug 11, 2026
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.
NoelStephensUnity commentedon Aug 12, 2026
@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.Singlebut 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)?
acavailhez commentedon Aug 18, 2026
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!
NoelStephensUnity commentedon Sep 25, 2026
@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?
michalChrobot commentedon Sep 25, 2026
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