Skip to content

Commit

Permalink
fix: don't consume so much memory registering prefabs (#486)
Browse files Browse the repository at this point in the history
In dragon's game, this can consume upwards of 30 GB of RAM
  • Loading branch information
paulpach committed Nov 7, 2020
1 parent 3b48d55 commit d451782
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Assets/Mirror/Editor/ClientObjectManagerInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,29 @@ public void RegisterPrefabs(ClientObjectManager gameObject)
gameObject.spawnPrefabs.AddRange(prefabs);
}

private static ISet<T> LoadPrefabsContaining<T>(string path) where T : UnityEngine.Component
private static ISet<T> LoadPrefabsContaining<T>(string path) where T : Component
{
var result = new HashSet<T>();

var guids = AssetDatabase.FindAssets("t:Object", new[] { path });
string[] guids = AssetDatabase.FindAssets("t:GameObject", new[] { path });

foreach (var guid in guids)
for (int i = 0; i< guids.Length; i++)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);

T obj = AssetDatabase.LoadAssetAtPath<T>(assetPath);

if (obj != null)
{
result.Add(obj);
}

if (i % 100 == 99)
{
EditorUtility.UnloadUnusedAssetsImmediate();
}
}
EditorUtility.UnloadUnusedAssetsImmediate();
return result;
}
}
Expand Down

0 comments on commit d451782

Please sign in to comment.