RPC Method
Options
Hey there. My problem:
I have a character with 3 materials.
material[0] for his cap color
material[1] for his jacket´s color
material[2] for his shoe´s color
when a player joins a room, I want the other players to ask his script for his clothing and i want them to change the new players masterials so its synced.
I used an RPC but this works only for players who are in the room, not for the player who joins the room.
Is there an easier way to sync materials for "playerskins"?
In my lobby manager:
The RPC in the PlayersManager:
Maybe there is an other way to do, but I cannot find a solution in the internet. Hope You can help me! Thx Toby!
I have a character with 3 materials.
material[0] for his cap color
material[1] for his jacket´s color
material[2] for his shoe´s color
when a player joins a room, I want the other players to ask his script for his clothing and i want them to change the new players masterials so its synced.
I used an RPC but this works only for players who are in the room, not for the player who joins the room.
Is there an easier way to sync materials for "playerskins"?
In my lobby manager:
int RandomPoint = Random.Range(-5, 5); GameObject player = PhotonNetwork.Instantiate(PlayerPrefab.name, new Vector3(RandomPoint, 0f, RandomPoint), Quaternion.identity, 0); PhotonView pv = PhotonView.Get(player); pv.RPC("ChangeClothing", RpcTarget.All, PlayerStats.PlayerClothingMale, pv.ViewID);
The RPC in the PlayersManager:
[PunRPC] void ChangeClothing(int[] clothes, int viewID) { GameObject targetPlayer = null; PlayerManager[] PlayerList = FindObjectsOfType<PlayerManager>(); foreach (PlayerManager p in PlayerList) { if (p.GetComponent<PhotonView>().ViewID == viewID) { targetPlayer = p.gameObject; break; } } if (targetPlayer != null) { var clothingMenu = targetPlayer.GetComponent<ClothingMenu>(); SkinnedMeshRenderer PlayerBody = targetPlayer.transform.Find("Male").GetComponentInChildren<SkinnedMeshRenderer>(); Material[] mats = PlayerBody.materials; //Material[] mats = targetPlayer.transform.Find("Boy01_Body_Geo").GetComponent<SkinnedMeshRenderer>().materials; //Material[] mats = targetPlayer.GetComponent<SkinnedMeshRenderer>().materials; mats[1] = clothingMenu.MaterialsTop[clothes[0]]; mats[2] = clothingMenu.MaterialsMid[clothes[1]]; mats[3] = clothingMenu.MaterialsBot[clothes[2]]; PlayerBody.materials = mats; } }
Maybe there is an other way to do, but I cannot find a solution in the internet. Hope You can help me! Thx Toby!
0
Comments
-
How about PlayerProperties? it can goes even before Instantiate.
when the Player Instantiated try load data from owner's player properties, and update when player properties updated.0 -
Hi @Toby,
Thank you for choosing Photon!
As @ThomasKao_XRSpace mentioned, actor properties is an option.
But you could also: make the RPC Buffered (RpcTarget.AllBuffered) so the event will be cached and sent to newly joined actors or rejoining ones.
You could also send custom instantiation data.0