- Home /
Photon Instantiating and Finding Problems...
Hi guys, so iv received a wee bug while using Photon and I cant figure out whats wrong with it... It works, fine in the editor and when only one person is on the server. So when a player joins the server their canvas panel is initiated and is then that is parented to the canvas and then a certain button is initiated to the canvas panel. However, when the second player joins, the panel and canvas are instigated but they can't seem to find the canvas or canvas panel(in the buttons case) and I can't figure for the life of me why? Any thanks would be greatly appreciated. Here is my code :
if (photonView.isMine)
{
GameObject uiGo = PhotonNetwork.Instantiate(playerUiPrefab.name, new Vector3(this.transform.position.x,
this.transform.position.y, 0), Quaternion.identity, 0) as GameObject;
playerJoyStick = GameObject.FindGameObjectWithTag("PlayerJoyStick").GetComponentInChildren();
if(playerJoyStick == null)
{
print("IM NULL");
}
uiGo.GetComponent().SetParent(GameObject.Find("Canvas").GetComponent(), false);
}
that is the code for instantiating the canvas panel and then parenting it the canvas game object. And here is the code for the buttons:
if(photonView.isMine)
{
alarmButton = PhotonNetwork.Instantiate(alarmButtonPrefab.name, new Vector3(this.transform.position.x + 50,
this.transform.position.y, 0), Quaternion.identity, 0) as GameObject;
Button alarmBut = alarmButton.GetComponent();
alarmBut.onClick.AddListener(() => { DeactivateAlarms(); });
}
private void Update()
{
if(photonView.isMine)
{
alarmButton.GetComponent().SetParent(GameObject.FindGameObjectWithTag("PlayerControls").GetComponent(), false);
}...
Any help would be amazing! Thank you
Answer by airbagnr1 · Feb 18, 2018 at 03:20 PM
Hi, if anyone in the future is having issues with this or something similar, as a workaround I simply made separate canvases for the players and just instantiated them normally(not using photon) so it would only be local to the player. Hope this helps anyone!