Synchronizing New Child Entities in NetCode ECS

I am performing collision detection on the server side in my Unity project.

I am trying to create a system where a character with a GhostAuthoringComponent can equip an item upon colliding with it. The item should become a child of the forwardCenterPointEntity.

I wrote the following code:

// set the equipment
var newEquip = ecb.Instantiate(prefabsData.W_FC_SmallNeedle);
ecb.SetName(newEquip, "W_FC_SmallNeedle");
ecb.AddComponent(newEquip, new Parent { Value = forwardCenterPointEntity });

On the server side, the item is correctly instantiated as a child of forwardCenterPointEntity. However, this is not synchronized on the client side.

Could you provide some hints or guidance on how to make this equipment system work properly?

Any help would be greatly appreciated.
Thank you.

スクリーンショット 2024-07-11 15.06.59

スクリーンショット 2024-07-11 15.08.24

スクリーンショット 2024-07-11 15.14.11

I might have found my mistake. I had the attributes for my system set up as follows:

public partial struct CharacterCollisionTriggerSystem : ISystem

This system primarily handles collision detection (RaiseTriggerEvents) for characters. The key point here is the WorldSystemFilter. Since I believe there is no point in handling collision detection on the client side, I have configured this system to run only on the server side.

However, I mistakenly instantiated weapons within this system.

Naturally, this means that weapons instantiated upon collision on the server side are not instantiated on the client side, since they are not Ghost entities. Additionally, I cannot attach a GhostAuthoringComponent to the weapon prefab because you cannot place a Ghost-Entity under another Ghost-Entity. If I attach a GhostAuthoringComponent to the weapon, I cannot set the character as the Parent of the weapon.

I am planning to address this by attaching a new DataComponent with a GhostField to the character and using the following strategy:

1.	Detect the collision on the server side.
2.	Attach a DataComponent with a GhostField to the character.
3.	On both the server and client sides, use the value from the GhostComponent to instantiate the weapon and set the character as the parent.

I am not sure if this is the best approach, but I hope it helps someone facing the same issue.

prefabsData.W_FC_SmallNeedle needs to become a Ghost (network-identifiable-prefab) to be even considered for synchronization.

I have tried adding a Ghost Authoring Component, AddComponent for GhostOwner, LinkedEntityGroup, but it does not work.

I really need help…

Read this documentation page to learn all about network spawning here:

I assume you’re familiar with “Networked Cube” example already
Networked Cube | Netcode for Entities | 1.0.17

I don’t know if this is a bug in NetCode, but I think it is not possible to add a parent-child relationship in the current NetCode.

I don’t think those documents and samples have the answer…
Nonetheless, thank you for your cooperation.

As an alternative solution I came up with, I attached theGhostAuthoringComponent
to the W-FC-SmallNeedle prefab and instantiated it without establishing a parent-child relationship with the Character. Then, I synchronized its Position and Rotation with the ForwardCenterPointEntity. Regarding collision detection, if possible, adding this weapon to the DynamicBuffer<PhysicsColliderKeyEntityPair> of the Character’s RigidBody might improve usability. It would be much easier if I could set up a parent-child relationship, but since I don’t know how to do that, I’m considering this method.