How do I change a Photon Instantiated GameObject (make changes to its child)?

I have seen that a similar post already exists but doesn't do any help.
I am trying this but I can't see any success.
My aim: to update a child gameobject (that is 3D Text) of a photon instantiated gameobject to its PhotonNetwork.playerName such that every other user in the network can see the change.

I use this to start Photon:
PhotonNetwork.ConnectUsingSettings("0.1");
PhotonNetwork.automaticallySyncScene = true;
PhotonNetwork.playerName= PlayerPrefs.HasKey("username") ? PlayerPrefs.GetString("username"):"User";
PhotonVoiceNetwork.Connect();

Upon joining the room:

public override void OnJoinedRoom()
{
PhotonNetwork.Instantiate("User", new Vector3(0, 1, 0), Quaternion.identity, 0);
GameObject.FindGameObjectWithTag("Navigation").transform.Find("UserClone" ).GetComponent().rpcnamesender1(); //to ensure that it doesn't select other userclone. Own userclone become child of navigation by default. Others dont.
}

In UserMovement:

[PunRPC]
public void rpcnamebroadcast( string namee)
{

this.transform.Find("Name").GetComponent().text = namee;
}
public void rpcnamesender1( )
{
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("rpcnamebroadcast", PhotonTargets.All, PhotonNetwork.playerName);
}

Comments

  • Hi @astonribat,

    you can use OnPhotonInstantiate for example. This will be processed when the game object gets created by calling PhotonNetwork.Instantiate, what you do in OnJoinedRoom. When using OnPhotonInstantiate, you also receive a PhotonMessageInfo which provides access to the player who sent the Instantiation call. Something like this:
    public void OnPhotonInstantiate(PhotonMessageInfo info)
    {
        GetComponentInChildren<TextMesh>().text = info.sender.NickName; // using a TextMesh component
    }
    If you have multiple components of the same type - means GetComponent doesn't work - make sure to add a reference to the component you want to modify.