Search Unity

Question How to set the parent of arrow to specific transform for all clients

Discussion in 'Netcode for GameObjects' started by Serinx, Jan 21, 2023.

  1. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    Hi All,

    When an arrow hits a target, I want it to stick to the target. This could be a tree, the ground, or a particular bone or a player (e.g. Head, Leg, or Arm), and have all clients see it stick to the same parent.

    I have a couple of issues with this:

    1. I can't set the parent to a tree of the ground because they are not NetworkObjects

    2. How do I tell the client exactly what collider was hit on a player?

    Thanks

    Edit: I'm hoping there's a generic solution like GetTransformWithId() that I can use for any Transform, and the Id is the same across all clients. I know I could just pass through a bone name and then tell the clients to attach the arrow to that bone.
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @Serinx , have you tried looking at the ClientDriven sample to see how it manages picking/dropping objects? It's basically the same use case
     
    Serinx likes this.
  3. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    @RikuTheFuffs-U Thanks for that reference, it's given me a few ideas but I had to go with another solution to solve my problems.

    I use a clientRPC to tell the clients to instantiate an instance of a "dummy" arrow at the specified position and name the bone/transform that I want to attach to. The client then looks for a transform with that name within the hit object.

    Unfortunately, parenting network objects to bones on a player is not possible in my tests.

    This piece of code was really helpful from the sample which allows me to identify the network object that got hit:


    Code (CSharp):
    1. public void PickupObjectServerRpc(ulong objToPickupID)
    2.     {      
    3.         NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(objToPickupID, out var objToPickup);
    Thanks for your help!