Skip to content

Commit 3904841

Browse files
committed
Spawn Prefab Performance Improvements
- Prefabs are now SetActive after Instatiating to the scene, rather than in the Process method. Loads 4k maps roughly 25% faster.
1 parent be8241f commit 3904841

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static GameObject Process(GameObject go, string filePath)
5555
}
5656
PrefabDataHolder prefabDataHolder = go.AddComponent<PrefabDataHolder>();
5757
prefabDataHolder.prefabData = new PrefabData() { id = AssetManager.ToID(filePath) };
58-
go.SetActive(true);
5958
return go;
6059
}
6160

@@ -67,14 +66,15 @@ public static void Spawn(GameObject go, PrefabData prefabData, Transform parent)
6766
newObj.transform.localScale = new Vector3(prefabData.scale.x, prefabData.scale.y, prefabData.scale.z);
6867
newObj.name = go.name;
6968
newObj.GetComponent<PrefabDataHolder>().prefabData = prefabData;
69+
newObj.SetActive(true);
7070
}
7171

7272
/// <summary>Spawns the prefab set in PrefabToSpawn at the spawnPos</summary>
7373
public static void Spawn(Vector3 spawnPos)
7474
{
7575
if (PrefabToSpawn != null)
7676
{
77-
GameObject.Instantiate(PrefabToSpawn, spawnPos, Quaternion.Euler(0, 0, 0), PrefabParent);
77+
GameObject.Instantiate(PrefabToSpawn, spawnPos, Quaternion.Euler(0, 0, 0), PrefabParent).SetActive(true);
7878
PrefabToSpawn = null;
7979
}
8080
}

0 commit comments

Comments
 (0)