- Home /
Failed Network.Instantiate because we are not connected. (when logs show i connect and joined room.)
can someone explain whats going on, I've connected, it joins lobby, it joins a room and my game starts awesome. then i go to click select player: (network.instantiate)
Network.Instantiate(Fighter01, SpawnPlayer.position, SpawnPlayer.rotation, 1);
and i get : Joined Lobby Joined Room Failed Network.Instantiate because we are not connected. .... didn't it just connect and join? nothing was turned of and nothing in the scene changes to make it logout.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Missioncontroll : Photon.MonoBehaviour {
const string VERSION = "0.1";
public string roomName = "GameRoom";
public float Timer = 500f; // amount of time before game with bots.
private bool inGame = false;
public NetworkView nView;
public static int IamPlayer = 0;
public int Maptoload = 0;
public GameObject ToggleOnOff;
public GameObject ToggleOnOff2;
//score controllers
public GameObject Player1;
public GameObject Player2;
public GameObject Player3;
public GameObject Player4;
public GameObject Player5;
//number of players in room (ICON)
public GameObject GameObjectPlayerIcon1;
public GameObject GameObjectPlayerIcon2;
public GameObject GameObjectPlayerIcon3;
public GameObject GameObjectPlayerIcon4;
public GameObject GameObjectPlayerIcon5;
public GameObject map1;
//TimerDisplay
public Text Timertext;
//------------------------------------------------------------------------------------------------------------
void Awake() {
Network.minimumAllocatableViewIDs = 500;
}
void Start(){
nView = GetComponent<NetworkView>();
Connect ();
}
//------------------------------------------------------------------------------------------------------------
void Connect(){
PhotonNetwork.ConnectUsingSettings (VERSION);
}
//------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------
void OnJoinedLobby () {
Debug.Log ("Joined Lobby");
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 5 };
PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
}
//--------------------------------------------------------------------------------------------------------------
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
//--------------------------------------------------------------------------------------------------------------
void OnJoinedRoom() {
Debug.Log ("Joined Room");
BotGameController.NumberofPlayers -= 1; //(add a player to the player counter)
if (PhotonNetwork.countOfPlayers == 0){
Player1.SetActive (true);
GameObjectPlayerIcon1.SetActive(true);
}
if (PhotonNetwork.countOfPlayers == 1){
Player1.SetActive (true);
IamPlayer = 1;
}
if (PhotonNetwork.countOfPlayers == 2){
Player2.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer2", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 2;
}
if (PhotonNetwork.countOfPlayers == 3){
Player3.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer3", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 3;
}
if (PhotonNetwork.countOfPlayers == 4){
Player4.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer4", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 4;
}
if (PhotonNetwork.countOfPlayers == 5){
Player5.SetActive (true);
NetworkViewID viewID = Network.AllocateViewID ();
nView.RPC ("Haveplayer5", RPCMode.AllBuffered, viewID, transform.position);
IamPlayer = 5;
}
}
//every time a player joins tell others in the room to set icons.
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer1(){
GameObjectPlayerIcon1.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer2(){
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
[PunRPC]
void Haveplayer3(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
}
[PunRPC]
void Haveplayer4(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
GameObjectPlayerIcon4.SetActive(true);
}
[PunRPC]
void Haveplayer5(){
GameObjectPlayerIcon1.SetActive(true);
GameObjectPlayerIcon2.SetActive(true);
GameObjectPlayerIcon3.SetActive(true);
GameObjectPlayerIcon4.SetActive(true);
GameObjectPlayerIcon5.SetActive(true);
}
//------------------------------------------------------------------------------------------------------------
void mapselectselect (){
//randomrange (mapselect) (consistent with all players so they all end up in same map.)
map1.SetActive(true);
ToggleOnOff.SetActive (false);
ToggleOnOff2.SetActive (true);
}
//------------------------------------------------------------------------------------------------------------
void LateUpdate (){
//loadmap automaticly after timer regadless of player count.
Timer -= 1;
if(Timer <1){
mapselectselect();
}
Timertext.text = "" + Timer.ToString();
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
{
if (stream.isWriting) {
// We own this player: send the others our data
stream.SendNext (inGame);
} else {
// Network player, receive data
this.inGame = (bool)stream.ReceiveNext ();
}
}
}
}
//------------------------------------------------------------------------------------------------------------
I don't see the Network.Instantiate line that's causing problems, in the code you posted.
oops my bad thats a different script forgot to post that to. using UnityEngine; using System.Collections;
public class StarfighterSelet : $$anonymous$$onoBehaviour {
public GameObject Fighter01;
public GameObject Fighter02;
public GameObject Camera1;
public GameObject ShipSelectGUI;
public GameObject GameGUI;
public Transform SpawnPlayer;
public void Fighter01Select () {
ShipSelectGUI.SetActive (false);
GameGUI.SetActive (true);
Network.Instantiate(Fighter01, SpawnPlayer.position, SpawnPlayer.rotation, 1);
}
public void Fighter02Select () {
ShipSelectGUI.SetActive (false);
GameGUI.SetActive (true);
Network.Instantiate(Fighter02, SpawnPlayer.position, SpawnPlayer.rotation, 1);
}
}
Your answer
Follow this Question
Related Questions
error spawning player says I'm not connected when photon connects and puts me in a room 0 Answers
Client Disconnect with message “Peer Created” - PUN 0 Answers
Networking problems 2 Answers
[Photon]Player vs. Player Collision 0 Answers
Correct way to design turn based multiplayer using Photon Unity Networking. 0 Answers