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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How can i sync changes to a objects parent?

Discussion in 'Multiplayer' started by xXGrime, Dec 19, 2015.

  1. xXGrime

    xXGrime

    Joined:
    Aug 19, 2014
    Posts:
    16
    Basically I instantiate a text object that represents a players name when they join the lobby. Then i calculate how many players are on each team and set the local players team based on this. < This works great.

    Here is where im stuck.

    Once that is done i loop through slots that are pre loaded in the scene(These are not instantiated) to see if they contain a child. If they dont then I parent the players text object to that slot.

    My problem is how can sync that change so all clients are aware of this change? Basically all im doing is trying to do is make something similar to what the call of duty score board looks like only its a lobby.
     
  2. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    I read in other places that, to change the parent of a game object, you need to do a Client RPC. Just modifying the transform.parent on the server is not enough and there're no other mechanisms than Client RPC that could do the trick...

    So you could add a Script next to your Text and, for each of these elements, the server will call a Client RPC on that script so that the client would, at its level, set the parent relation ship.

    [Edit]
    Another solution would be to have a Script next to each Text, with a sync var indicating to which team the element belongs to. When the client generates the score screen, it could do the wiring at that time. I believe that team changes and so on would be easier to support with such a solution.