Last active
April 21, 2022 10:28
-
-
Save lynxelia/b1a5680ccdac48d822c0d2844fc555a1 to your computer and use it in GitHub Desktop.
A Unity3d editor script that automatically forces garbage collection when opening a scene
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine.SceneManagement; | |
[InitializeOnLoad] | |
public static class EditorSceneMemoryManager | |
{ | |
static EditorSceneMemoryManager() | |
{ | |
EditorSceneManager.sceneOpened += OnSceneOpened; | |
} | |
static void OnSceneOpened(Scene scene, OpenSceneMode mode) | |
{ | |
GarbageCollect(); | |
} | |
[MenuItem("Tools/Force Garbage Collection")] | |
static void GarbageCollect() | |
{ | |
EditorUtility.UnloadUnusedAssetsImmediate(); | |
GC.Collect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment