Hello! I know there are quite a few threads on this topic, but I was not able to find a solution to mine with these.
I have a game that opens on a certain scene. Then, I call SceneManager.LoadSceneAsync(sceneName or sceneBuildIndex)
(or LoadScene
instead of the Async
version, same result anyway in my case). The exact code for the component I use is:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class SceneChanger : MonoBehaviour
{
public int sceneToLoadIndex;
private Collider2D selfCollider;
private IEnumerator LoadScene()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneToLoadIndex);
asyncLoad.allowSceneActivation = true;
while (!asyncLoad.isDone)
{
Debug.LogError(asyncLoad.progress);
yield return null;
}
yield return new WaitForEndOfFrame();
}
void Start()
{
selfCollider = GetComponent<Collider2D>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (selfCollider.OverlapPoint(mousePos))
StartCoroutine(LoadScene());
}
}
}
Note that I also tried just calling LoadScene
directly without the Coroutine stuff. I made sure to set the build indices to valid values, I tried with the scene names, and I even tried just using the current scene’s name to make sure the input is valid.
Well, in the editor, everything is fine. In the built game (compiled with Unity 2022.3.47f1 on Windows and Linux Debian), the executable just simply crashes when I click on a collider to change or reload the scene. Here is the log file obtained from a development build:
Mono path[0] = 'C:/Users/my-name/hss-histoire-des-sciences/Build/PolarimetreBiotSavart_Data/Managed'
Mono config path = 'C:/Users/my-name/hss-histoire-des-sciences/Build/MonoBleedingEdge/etc'
Starting managed debugger on port 56347
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=0.0.0.0:56347
Found 1 interfaces on host : 0) 192.168.1.33
Player connection [22828] Target information:
Player connection [22828] * "[IP] 192.168.1.33 [Port] 55000 [Flags] 2 [Guid] 3134670347 [EditorId] 912228071 [Version] 1048832 [Id] WindowsPlayer(2,LAPTOP-Q8EP6VDQ) [Debug] 1 [PackageName] WindowsPlayer [ProjectName] PolarimetreBiotSavart"
Player connection [22828] Started UDP target info broadcast (1) on [225.0.0.222:54997].
[PhysX] Initialized MultithreadedTaskDispatcher with 16 workers.
Initialize engine version: 2022.3.47f1 (88c277b85d21)
[Subsystems] Discovering subsystems at path C:/Users/my-name/hss-histoire-des-sciences/Build/PolarimetreBiotSavart_Data/UnitySubsystems
GfxDevice: creating device client; threaded=1; jobified=0
Direct3D:
Version: Direct3D 11.0 [level 11.1]
Renderer: NVIDIA GeForce RTX 3070 Laptop GPU (ID=0x249d)
Vendor: NVIDIA
VRAM: 8044 MB
Driver: 30.0.15.1274
Begin MonoManager ReloadAssembly
- Loaded All Assemblies, in 2.060 seconds
- Finished resetting the current domain, in 0.001 seconds
<RI> Initializing input.
<RI> Input initialized.
<RI> Initialized touch support.
[PhysX] Initialized MultithreadedTaskDispatcher with 16 workers.
UnloadTime: 1.846600 ms
Unloading 5 Unused Serialized files (Serialized files now loaded: 0)
[PhysX] Initialized MultithreadedTaskDispatcher with 16 workers.
UnloadTime: 5.243800 ms
Unloading 13 unused Assets / (3.6 KB). Loaded Objects now: 1707.
Memory consumption went from 69.7 MB to 69.7 MB.
Total: 1.415300 ms (FindLiveObjects: 0.151800 ms CreateObjectMapping: 0.072700 ms MarkObjects: 0.977100 ms DeleteObjects: 0.213100 ms)
PlayerConnection::CleanupMemory Statistics:
[ALLOC_TEMP_TLS] TLS Allocator
StackAllocators :
[ALLOC_TEMP_MAIN]
Peak usage frame count: [4.0 KB-8.0 KB]: 354 frames, [8.0 KB-16.0 KB]: 39 frames, [2.0 MB-4.0 MB]: 1 frames
Initial Block Size 4.0 MB
Current Block Size 4.0 MB
Peak Allocated Bytes 2.1 MB
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 8]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 10]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 4]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_AUDIO_FMOD (WASAPI) feeder thread]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 168 B
Overflow Count 0
[ALLOC_TEMP_AUDIO_FMOD mixer thread]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 1]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 6]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 11]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 3]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_BatchDeleteObjects]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_AUDIO_FMOD stream thread]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 13]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 2]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 7]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 8]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 1]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 4.9 KB
Overflow Count 0
[ALLOC_TEMP_Job.Worker 10]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 12]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Loading.PreloadManager]
Initial Block Size 256.0 KB
Current Block Size 296.0 KB
Peak Allocated Bytes 290.7 KB
Overflow Count 8
[ALLOC_TEMP_Background Job.Worker 15]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Profiler.Dispatcher]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 456 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 14]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 3]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 12]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_AssetGarbageCollectorHelper] x 15
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 138 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 5]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 13]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 2]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 192 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 0]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 11]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 4]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 0]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 5]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 14]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 6]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_EnlightenWorker] x 8
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_UnityGfxDeviceWorker]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 13.4 KB
Overflow Count 0
[ALLOC_TEMP_Job.Worker 9]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Background Job.Worker 9]
Initial Block Size 32.0 KB
Current Block Size 32.0 KB
Peak Allocated Bytes 54 B
Overflow Count 0
[ALLOC_TEMP_Job.Worker 7]
Initial Block Size 256.0 KB
Current Block Size 256.0 KB
Peak Allocated Bytes 16 B
Overflow Count 0
[ALLOC_TEMP_Loading.AsyncRead]
Initial Block Size 64.0 KB
Current Block Size 64.0 KB
Peak Allocated Bytes 380 B
Overflow Count 0
[ALLOC_MEMORYPROFILER]
Peak usage frame count: [64.0 KB-128.0 KB]: 150 frames, [128.0 KB-256.0 KB]: 244 frames
Requested Block Size 1.0 MB
Peak Block count 1
Peak Allocated memory 251.3 KB
Peak Large allocation bytes 0 B
[ALLOC_DEFAULT] Dual Thread Allocator
Peak main deferred allocation count 1652
[ALLOC_BUCKET]
Large Block size 4.0 MB
Used Block count 1
Peak Allocated bytes 2.2 MB
[ALLOC_DEFAULT_MAIN]
Peak usage frame count: [16.0 MB-32.0 MB]: 394 frames
Requested Block Size 16.0 MB
Peak Block count 2
Peak Allocated memory 25.7 MB
Peak Large allocation bytes 8.0 MB
[ALLOC_DEFAULT_THREAD]
Peak usage frame count: [16.0 MB-32.0 MB]: 394 frames
Requested Block Size 16.0 MB
Peak Block count 1
Peak Allocated memory 22.4 MB
Peak Large allocation bytes 16.0 MB
[ALLOC_TEMP_JOB_1_FRAME]
Initial Block Size 2.0 MB
Used Block Count 0
Overflow Count (too large) 0
Overflow Count (full) 0
[ALLOC_TEMP_JOB_2_FRAMES]
Initial Block Size 2.0 MB
Used Block Count 0
Overflow Count (too large) 0
Overflow Count (full) 0
[ALLOC_TEMP_JOB_4_FRAMES (JobTemp)]
Initial Block Size 2.0 MB
Used Block Count 1
Overflow Count (too large) 0
Overflow Count (full) 0
[ALLOC_TEMP_JOB_ASYNC (Background)]
Initial Block Size 1.0 MB
Used Block Count 1
Overflow Count (too large) 0
Overflow Count (full) 0
[ALLOC_GFX] Dual Thread Allocator
Peak main deferred allocation count 1
[ALLOC_BUCKET]
Large Block size 4.0 MB
Used Block count 1
Peak Allocated bytes 2.2 MB
[ALLOC_GFX_MAIN]
Peak usage frame count: [32.0 KB-64.0 KB]: 146 frames, [64.0 KB-128.0 KB]: 248 frames
Requested Block Size 16.0 MB
Peak Block count 1
Peak Allocated memory 112.1 KB
Peak Large allocation bytes 0 B
[ALLOC_GFX_THREAD]
Peak usage frame count: [2.0 KB-4.0 KB]: 147 frames, [4.0 KB-8.0 KB]: 247 frames
Requested Block Size 16.0 MB
Peak Block count 1
Peak Allocated memory 6.0 KB
Peak Large allocation bytes 0 B
[ALLOC_CACHEOBJECTS] Dual Thread Allocator
Peak main deferred allocation count 33
[ALLOC_BUCKET]
Large Block size 4.0 MB
Used Block count 1
Peak Allocated bytes 2.2 MB
[ALLOC_CACHEOBJECTS_MAIN]
Peak usage frame count: [2.0 MB-4.0 MB]: 394 frames
Requested Block Size 4.0 MB
Peak Block count 1
Peak Allocated memory 2.4 MB
Peak Large allocation bytes 0 B
[ALLOC_CACHEOBJECTS_THREAD]
Peak usage frame count: [16.0 MB-32.0 MB]: 394 frames
Requested Block Size 4.0 MB
Peak Block count 6
Peak Allocated memory 30.4 MB
Peak Large allocation bytes 10.6 MB
[ALLOC_TYPETREE] Dual Thread Allocator
Peak main deferred allocation count 0
[ALLOC_BUCKET]
Large Block size 4.0 MB
Used Block count 1
Peak Allocated bytes 2.2 MB
[ALLOC_TYPETREE_MAIN]
Peak usage frame count: [4.0 KB-8.0 KB]: 147 frames, [8.0 KB-16.0 KB]: 247 frames
Requested Block Size 2.0 MB
Peak Block count 1
Peak Allocated memory 9.6 KB
Peak Large allocation bytes 0 B
[ALLOC_TYPETREE_THREAD]
Peak usage frame count: [4.0 KB-8.0 KB]: 394 frames
Requested Block Size 2.0 MB
Peak Block count 1
Peak Allocated memory 7.7 KB
Peak Large allocation bytes 0 B
[ALLOC_PROFILER]
Peak usage frame count: [256.0 KB-0.5 MB]: 393 frames, [32.0 MB-64.0 MB]: 1 frames
Requested Block Size 16.0 MB
Peak Block count 3
Peak Allocated memory 33.3 MB
Peak Large allocation bytes 0 B
[ALLOC_PROFILER_BUCKET]
Large Block size 4.0 MB
Used Block count 1
Peak Allocated bytes 66.0 KB
##utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1735920170760,"processId":6660,"allocatedMemory":572703,"memoryLabels":[{"Default":-128},{"NewDelete":80},{"Manager":533992},{"GfxDevice":72},{"Serialization":508},{"JobScheduler":32768},{"String":163},{"HashMap":3072},{"PoolAlloc":168},{"VR":1784},{"Subsystems":96},{"CoreBusinessMetrics":128}]}
Sounds like a memory leak issue but I’m kind of a newbie, so I don’t have any way to solve this on my own. Thank you in advance for helping me out and have a nice day/evening!