Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to track position of a child of a Network object.

Discussion in 'Netcode for GameObjects' started by SamohtVII, May 16, 2023.

  1. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    364
    I have a player variant prefab that is obviously the player spawned in.
    It has a Gameobject in it that is doing some raycast to find out where they are looking. Basically the first object it hits it moves to that point in the world.
    I have attached a Network Object and Network Transform on it but it doesn't seem to be syncing to the server.
    The player on the server just keeps staring at the same point.

    Firstly, do I need a second Network Object on children objects?
    Do I need to "Spawn()" it in for it to be syncable?
    Am I missing some simple logic?
    Thanks
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    Hi @SamohtVII , it's a bit hard to answer your latest questions without seeing your code, hoe yout scene is setup, and who is doing what.
    Apart from this, did you have a look at ClientNetworkTransform already? That might be a good starting point.
     
  3. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    364
    Sorry that was poorly explained.

    I have a player Variant with hierarchy like this

    Player
    - Bone
    - Rig
    - Cameras
    - CharacterAimAt

    The CharacterAimAt object has a script on it that will draw a ray from the center of the camera outwards until it hits a gameobject (Like the ground or another player etc), and will position the CharacterAimAt object at this point.

    My Player has a NetworkObject on it (No Network Transform) and I also want to track the Network Transform of the point in space that the CharacterAimAt is tracking (Basically just track that GO). Simply adding the Network Transform script onto it doesn't seem to track it at all.

    Am I doing something wrong? How can I make this server authoritive? It should just track right?
    Does the object need to be Spawned()?

    I hope that explains it better.

    Thanks
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    Thanks for explaining!

    Is it a NetworkObject too?

    Everythign that needs to besynchronized over the network needs to be Spawned(). Until you do that, nothing about that object will be synchronized
     
  5. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    364
    The Player is Spawned in and is running fine on the server so I know that is synced. The child object CharacterAimAt does not have a Network Object on it only the Player does. I hope this screenshot helps.
     

    Attached Files: