diff --git a/ValheimPerformanceOptimizations/Patches/ZNetViewPrefabNamePatch.cs b/ValheimPerformanceOptimizations/Patches/ZNetViewPrefabNamePatch.cs index f3e6230..192956f 100644 --- a/ValheimPerformanceOptimizations/Patches/ZNetViewPrefabNamePatch.cs +++ b/ValheimPerformanceOptimizations/Patches/ZNetViewPrefabNamePatch.cs @@ -41,8 +41,8 @@ private static bool Prefix(ZNetView __instance, ref string __result) __result = PrefabNameHack ?? Utils.GetPrefabName(__instance.gameObject); return false; } - - + + // this gets overwritten if object pooling is enabled [HarmonyTranspiler, HarmonyPatch(typeof(ZoneSystem), "PlaceVegetation")] public static IEnumerable Transpile_ZoneSystem_PlaceVegetation( IEnumerable instructions) diff --git a/ValheimPerformanceOptimizations/Patches/ZoneSystemObjectPoolingPatch.cs b/ValheimPerformanceOptimizations/Patches/ZoneSystemObjectPoolingPatch.cs index 434503e..36f87e9 100644 --- a/ValheimPerformanceOptimizations/Patches/ZoneSystemObjectPoolingPatch.cs +++ b/ValheimPerformanceOptimizations/Patches/ZoneSystemObjectPoolingPatch.cs @@ -71,7 +71,6 @@ public static void Postfix(ZoneSystem __instance) var toPool = vegetationForName.Aggregate(0, (acc, veg) => acc + (int) (veg.m_max * veg.m_groupSizeMax * _pooledObjectCountMultiplier.Value)); - ValheimPerformanceOptimizations.Logger.LogInfo($"Total pooled objects {toPool} {prefab.name}"); var pool = new GameObjectPool(prefab, toPool, OnRetrievedFromPool); if (prefab.GetComponentInChildren()) @@ -216,7 +215,8 @@ private static void OnRetrievedFromPool(GameObject obj) var netView = obj.GetComponent(); netView.Awake(); - if (PrefabsWithFadeComponent.Contains(obj.name)) + var prefabName = ZNetViewPrefabNamePatch.PrefabNameHack ?? obj.name; + if (PrefabsWithFadeComponent.Contains(prefabName)) { // some prefabs have their lod fade on the second level obj.GetComponentInChildren().Awake(); @@ -229,6 +229,8 @@ public static GameObject GetOrInstantiateObject( { GameObject gameObject; var pool = GetPoolForObject(prefab); + + ZNetViewPrefabNamePatch.PrefabNameHack = prefab.name; if (mode == ZoneSystem.SpawnMode.Ghost && pool != null) { gameObject = pool.GetObject(position, rotation); @@ -238,6 +240,8 @@ public static GameObject GetOrInstantiateObject( gameObject = Object.Instantiate(prefab, position, rotation); } + ZNetViewPrefabNamePatch.PrefabNameHack = null; + gameObject.name = prefab.name; return gameObject;