Search Unity

Question Synchronization of Child Transforms, best practices

Discussion in 'NetCode for ECS' started by DecoFox, Feb 21, 2024.

  1. DecoFox


    Sep 13, 2019
    I'm relatively new to DOTS and still trying to get to grips with the theory of it, so bear with me here:

    I'm in a situation where I need to replicate a rotation on a transform that is the child of a ghost. In my case this is for aim IK, but the situation is functionally more or less identical to a turret on a vehicle. Right now my character controller is entirely server-authoritative, which works great as long as I'm only working with the root transform of my ghost. Trouble is, in order to drive my IK system, I need to move a transform childed to that ghost to serve as an IK target. I wrote a system to do this on the server, but naturally the movement doesn't replicate because the target child is not itself a ghost. After a day or so of research, it seems like I have a few options:

    1. Make the target a GhostChildEntity and assign it to the player prefab's GhostGroup
    2. Something having to do with GhostComponentAttribute and SendDataForChildEntity (mentioned here:, but I haven't had much luck turning up what exactly this does or how to implement it.
    3. Don't control the IK target on the server at all. Leave it on the client.

    My understanding so far:

    I started today chasing option 1, but I haven't had much luck working out how to actually assign a GhostChildEntity to a GhostGroup somewhere on a parent. I understand this assignment has to be done at runtime, but I'm not clear on how I would get, be it by ijobentity or foreach, a reference to both the GhostChildEntity and GhostGroup and know I was looking at the correct pair of them.

    My efforts to understand how to do this led me through a couple of posts that suggested to me I might be barking up the wrong tree anyway, and that a GhostGroup would be a very expensive solution for a relatively simple problem, but I'm not sure. In any case I'd still appreciate some clarification on how this is best done, as I'm pretty sure I will have to resort to it for the weapons themselves.

    Honestly no idea what's going on with these right now or whether they're the tool for the job.

    This I think I could do pretty easily. I'm already synchronizing a HeadPitch float ghostfield to drive the player camera, so it wouldn't be out of my way to write a clientside ISystem to drive the IK targets too. This is a bit different from the camera though in that it would have to operate on each client for every player connected to the server (rather than just the local ghost owner), and from a structural perspective I'm not a huge fan of running aim IK for all players on the every client while every other character controller feature is handled by the server. I'm not convinced this isn't the best approach, it just feels "icky" to me in a way that makes me think there's a better solution.

    Which of these approaches, if any, should I be pursuing? Am I totally barking up the wrong trees here?