Instantiate isn't working?

Options
Hi, I've used PUN before and never really had any issues and I've used this exact same code before in previous projects but it just isn't working for some reason. It's meant to instantiate a player prefab but there are no errors at all, it's like it's either skipping instantiate or it's running successfully and spawning in nothing as there are no (Clone)'s added to the heirachy.
private void SpawnPlayer() {
		if (BlueSpawns == null || RedSpawns == null) {
			Debug.Log("NO SPAWN POINTS FOUND");
			return;
		}

		if (PhotonNetwork.player.GetTeam () == PunTeams.Team.blue) {
			GameObject Spawn = BlueSpawns[Random.Range(0, BlueSpawns.Length -1)];

			GameObject myPlayer = (GameObject)PhotonNetwork.Instantiate("PlayerPrefab", Spawn.transform.position, Spawn.transform.rotation, 1);

			((MonoBehaviour)myPlayer.GetComponent<PlayerMovement>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<IronSight>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<PlayerAttack>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<CameraX>()).enabled = true;

			myPlayer.transform.FindChild("PlayerCamera").gameObject.SetActive(true);
		}

		if (PhotonNetwork.player.GetTeam () == PunTeams.Team.red) {
			GameObject Spawn = RedSpawns[Random.Range(0, RedSpawns.Length -1)];

			GameObject myPlayer = PhotonNetwork.Instantiate("PlayerPrefab", Spawn.transform.position, Spawn.transform.rotation, 2) as GameObject;

			((MonoBehaviour)myPlayer.GetComponent<PlayerMovement>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<IronSight>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<PlayerAttack>()).enabled = true;
			((MonoBehaviour)myPlayer.GetComponent<CameraX>()).enabled = true;
			
			myPlayer.transform.FindChild("PlayerCamera").gameObject.SetActive(true);
		}
	}

Comments

  • Tobias
    Options
    It's hard to help without knowing the whole project.
    I would add Debug.Log() before your Instantiate calls. See if they get called.
    If they are not, you can add Debug.Log() earlier and see if GetTeam() gets you a fitting value, etc.
    PUN should log some warning if a PlayerPrefab is not in a Resources folder. Maybe you increase the log level?