diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs index df75194fe5..a7d77c3e1a 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs @@ -38,34 +38,35 @@ private void SetupObject(WorldEntity entity, Optional parent, GameOb CrafterLogic.NotifyCraftEnd(gameObject, techType); WaterPark parentWaterPark = parent.HasValue ? parent.Value.GetComponent() : null; - if (!parentWaterPark) + + if (parent.HasValue) { - if (parent.HasValue && !parent.Value.GetComponent()) - { - LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject - } - else if (gameObject.GetComponent() && !gameObject.transform.parent && cellRoot.liveRoot) + if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable)) { - gameObject.transform.SetParent(cellRoot.liveRoot.transform, true); - LargeWorldEntity.Register(gameObject); + pickupable.SetVisible(false); + pickupable.Activate(false); + parentWaterPark.AddItem(pickupable); } else { - gameObject.SetActive(true); + gameObject.transform.SetParent(parent.Value.transform, true); } } - if (parent.HasValue) + if (!parentWaterPark) { - if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable)) + if (parent.HasValue && !parent.Value.GetComponent()) { - pickupable.SetVisible(false); - pickupable.Activate(false); - parentWaterPark.AddItem(pickupable); + LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject + } + else if (gameObject.GetComponent() && cellRoot.liveRoot) + { + gameObject.transform.SetParent(cellRoot.liveRoot.transform, true); + LargeWorldEntity.Register(gameObject); } else { - gameObject.transform.SetParent(parent.Value.transform, true); + gameObject.SetActive(true); } } } diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs index 6fd25271eb..f7cf7c73f9 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs @@ -28,7 +28,7 @@ public IEnumerator SpawnAsync(WorldEntity entity, Optional parent, E yield break; } - SetupObject(entity, result.value.Value); + SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject); } public bool SpawnsOwnChildren() => false; @@ -45,7 +45,7 @@ public bool SpawnSync(WorldEntity entity, Optional parent, EntityCel return false; } - SetupObject(entity, result.value.Value); + SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject); return true; } @@ -63,10 +63,14 @@ private bool VerifyCanSpawnOrError(WorldEntity entity, Optional pare return false; } - private void SetupObject(WorldEntity entity, GameObject gameObject) + private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject parent) { - gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); - gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); - gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); + if (entity is PrefabPlaceholderEntity prefabEntity && !prefabEntity.IsEntitySlotEntity && parent) + { + gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); + gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); + gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); + gameObject.transform.SetParent(parent.transform, false); + } } } diff --git a/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs b/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs index 293254148e..ee743b9b00 100644 --- a/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs +++ b/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs @@ -16,13 +16,16 @@ public class PrefabPlaceholderEntity : WorldEntity [DataMember(Order = 1)] public int ComponentIndex { get; set; } + [DataMember(Order = 2)] + public bool IsEntitySlotEntity { get; set; } + [IgnoreConstructor] protected PrefabPlaceholderEntity() { // Constructor for serialization. Has to be "protected" for json serialization. } - public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0) + public PrefabPlaceholderEntity(WorldEntity worldEntity, bool isEntitySlotEntity, int componentIndex = 0) { Id = worldEntity.Id; TechType = worldEntity.TechType; @@ -34,14 +37,16 @@ public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0) SpawnedByServer = worldEntity.SpawnedByServer; ChildEntities = worldEntity.ChildEntities; ComponentIndex = componentIndex; + IsEntitySlotEntity = isEntitySlotEntity; } /// Used for deserialization - public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List childEntities, int componentIndex) : + public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List childEntities, bool isEntitySlotEntity, int componentIndex) : base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities) { ComponentIndex = componentIndex; + IsEntitySlotEntity = isEntitySlotEntity; } public override string ToString() diff --git a/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs b/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs index 131fcce7b0..c4204afe98 100644 --- a/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs +++ b/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs @@ -392,7 +392,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity } else { - spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i); + spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, true, i); } entity.ChildEntities.Add(spawnedEntity); } @@ -415,7 +415,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity } else { - spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i); + spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, false, i); } entity.ChildEntities.Add(spawnedEntity);