Error: Failed to instantiate prefab - Client should be in a room

Hi everyone, I'm completely new to PUN, it looks great and just what you need if you want to try making small, deathmatch style gaming and so on but I've run into a problem with PhotonNetwork.Instantiate.

I had almost got everything working but I can't seem to spawn in my tank.

I am currently following the youtube tutorial above which is a bit oudated and I'm trying to figure out where I've gone wrong, it's all really simple, get the room set up, connect then spawn the tank onto a random point in the game world, then I get this error.

Error: Failed to Instantiate prefab: TankPrefab. Client should be in a room. Current connectionStateDetailed: JoinedLobby

Just connecting to the lobby by itself works fine, so I must have gone wrong with the instantiate code somehow.

using UnityEngine; using System.Collections; public class NetworkManager : MonoBehaviour { SpawnPoint[] spawnPoints; // Use this for initialization void Start () { spawnPoints = GameObject.FindObjectsOfType (); Connect (); } void Connect () { PhotonNetwork.ConnectUsingSettings ("TankFight 1.0"); } void OnGUI () { GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ()); } void OnJoinedLobby () { Debug.Log ("OnJoinedRandomLobbySuccess"); PhotonNetwork.JoinRandomRoom (); OnJoinedRoom (); } void OnPhotonRandomJoinedFailed () { Debug.Log ("JoinedRandomLobbyFailed"); PhotonNetwork.CreateRoom (null); { Debug.Log ("Room Created"); } } void OnJoinedRoom () { Debug.Log ( "OnJoinedRoom Initiated" ); SpawnMyPlayer (); } void SpawnMyPlayer () { SpawnPoint mySpawnPoint = spawnPoints [Random.Range (0, spawnPoints.Length)]; PhotonNetwork.Instantiate (("TankPrefab"), mySpawnPoint.transform.position, Quaternion.identity, 0); Debug.Log ("Player Spawned Correctly"); if ( spawnPoints == null ) { Debug.Log ("Player Spawn Failed!"); return; } } }

Oddly enough, it claims that I've connected regardless and the debug log says SpawnMyPlayer has gone through without any problems.


  • Just so people know, I found I went to a more up to date tutorial and using the code from that fixed everything.

    Going to start looking at multiple spawnpoints etc. now and see if I can find anything up to date on that.
Sign In or Register to comment.