Skip to content

Commit a79cef8

Browse files
committed
Network.Spawn identity'd blocks
1 parent 12bc9ac commit a79cef8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Runtime/Code/VoxelWorld/VoxelWorldChunk.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using BlockId = System.UInt16;
77
using System.Runtime.CompilerServices;
88
using System.Threading.Tasks;
9+
using Mirror;
910
using UnityEngine.Profiling;
1011
using UnityEngine.Rendering;
1112
using Object = UnityEngine.Object;
@@ -229,10 +230,25 @@ private void FullInstatiatePrefabsMainThread() {
229230
continue;
230231
}
231232

233+
var isNetworked = false;
232234
GameObject prefabDef = blockDefinition.definition.prefab;
235+
if (prefabDef.GetComponent<NetworkIdentity>()) isNetworked = true;
236+
237+
// If client and networked prefab, do not spawn on client
238+
if ((!RunCore.IsServer() && isNetworked) && Application.isPlaying) {
239+
continue;
240+
}
241+
233242
var rotationBits = VoxelWorld.GetVoxelFlippedBits(voxelData);
234243
var rot = VoxelWorld.FlipBitsToQuaternion(rotationBits);
235-
GameObject prefab = GameObject.Instantiate(prefabDef, origin + localChunkPos, rot, obj.transform);
244+
245+
var prefab = Object.Instantiate(prefabDef, origin + localChunkPos, rot, obj.transform);
246+
if (isNetworked && Application.isPlaying) {
247+
NetworkServer.Spawn(prefab);
248+
var networker = world.worldNetworker;
249+
// Probably need to signal to client to add this as well :s
250+
}
251+
236252
prefab.transform.parent = obj.transform;
237253
prefab.transform.localScale = Vector3.one;
238254

0 commit comments

Comments
 (0)