- Home /
Changing a network object.
Is there a way to change/update/modify a networked player's object after it's been instantiated? I assuming I'm not using the incorrect keywords for searches, because I can't find anything about how to do this.
All of the networking examples I've seen, are referring to instantiating cubes. So, let us assume I have multiple players (like eight of them) that are connected to separate server. Each player has been assigned a human prefab when they connected. One of them runs around and finds a pair of pants. When they put the pants on. How can an RPC be used to update the other players, so they too can see the pants? Obviously the pants have to be a prefab too.
Or can someone point me in the correct direction?
Answer by Borzi · Nov 29, 2013 at 06:43 PM
Well I don't know exactly how you want to add the pants but usually anything network related should work with RPC's and sync with other players. The hard thing with Networking is that there are many ways to do it and no right one either. I'll show you something I would do (and that I hope works for you):
public Transform Pants;
public bool PantsCollected;
void Update()
{
//If the Pants were Collected
if(PantsCollected = true)
{
//Activate the Pants
Pants.gameObject.SetActiveRecursively(true);
}
[RPC]
void CollectPants
{
//Call this function to set the pants to true. With the RPC it will sync to all players
PantsCollected = true;
}
This way, the Pants will be visible to all players as "PantsCollected" will be true for everyone on the network (meaning that the other players will recognise the pants as collected and able to see them on your player). This might not be what you want at all of course and I am by no means a very good programmer, yet I still hope that this helped you. Cheers!
Your answer
![](https://koobas.hobune.stream/wayback/20220613123052im_/https://answers.unity.com/themes/thub/images/avi.jpg)