How can i sync changes to a objects parent?

Options
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.

I tried to serialize the array of slots but due to them being gameobjects that does not work. I also tried to rpc with buffer the parenting method but that also did not work.

Comments

  • vadim
    Options
    You can synchronize parenting as any other property, via RPC or OnPhotonSerializeView e.g.
    If slots are PhotonView objects, you can reference them by viewID. Otherwise, put slot objects in array kept in one of scene scripts. That way, you get same arrays on all clients and can reference spawn points by index in this array.
    Note that in this case you don't even need to synchronize something since all players join in the same order on all clients. Just run same slot selection logic on all clients.
    With viewID's, you can avoid synchronization by almost same way.
  • xXGriMe
    xXGriMe
    edited December 2015
    Options
    vadim said:

    Otherwise, put slot objects in array kept in one of scene scripts. That way, you get same arrays on all clients and can reference spawn points by index in this array.
    Note that in this case you don't even need to synchronize something since all players join in the same order on all clients. Just run same slot selection logic on all clients.
    With viewID's, you can avoid synchronization by almost same way.

    This is what im doing but for some reason i dont get the same results from every client. Here are my two methods that handle this. sofSlots and savageSlots are the arrays present in my scene script. Things seem to go good until the 3rd client joins. After that players start getting place in the wrong slots.

    public void SetOtherPlayersParent() { foreach (PhotonPlayer player in PhotonNetwork.otherPlayers) { if ((string)player.customProperties ["Team"] == "Sof" && !photonView.isMine) { foreach (GameObject sofSlots in gameLobbyScript.sofPlayers) { if (sofSlots.transform.childCount == 0&& !photonView.isMine) { transform.SetParent (sofSlots.gameObject.transform, false); break; } } } else if ((string)player.customProperties ["Team"] == "Savage" && !photonView.isMine) { foreach (GameObject savageSlots in gameLobbyScript.savagesPlayers) { if (savageSlots.transform.childCount == 0&& !photonView.isMine) { transform.SetParent (savageSlots.gameObject.transform, false); break; } } } } } public void SetPlayersParent() { if ((string)PhotonNetwork.player.customProperties ["Team"] == "Sof" && photonView.isMine) { foreach (GameObject sofSlots in gameLobbyScript.sofPlayers) { if (sofSlots.transform.childCount == 0) { transform.SetParent (sofSlots.gameObject.transform, false); break; } } } if ((string)PhotonNetwork.player.customProperties ["Team"] == "Savage" && photonView.isMine) { foreach (GameObject savageSlots in gameLobbyScript.savagesPlayers) { if (savageSlots.transform.childCount == 0) { transform.SetParent (savageSlots.gameObject.transform, false); break; } } } }
  • xXGriMe
    Options
    Solved.