weird view id (-999)

[code2=csharp]using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour
{
public bool eOffline = true;


// Use this for initialization
void Start()
{
PhotonNetwork.offlineMode = eOffline;
Connect();
}

void Connect()
{
PhotonNetwork.ConnectUsingSettings ("0.0.1");
}

void OnGUI()
{
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}

void OnJoinedLobby ()
{
PhotonNetwork.JoinRandomRoom ();
}

void OnPhotonRandomJoinFailed ()
{
PhotonNetwork.CreateRoom (null);
SpawnMe ();
}

void SpawnMe()
{
GameObject MyPlayer = (GameObject)PhotonNetwork.Instantiate ("PlayerController", Vector3.zero, Quaternion.identity, 0);
((MonoBehaviour)MyPlayer.GetComponent ("MouseLook")).enabled = true;
((MonoBehaviour)MyPlayer.GetComponent ("FPSInputController")).enabled = true;
MyPlayer.transform.FindChild ("Main Camera").gameObject.SetActive(true);
print(MyPlayer.GetComponent<PhotonView>().viewID);
}
}[/code2]

When i start the game i'm getting log:
[code2=csharp]print(MyPlayer.GetComponent<PhotonView>().viewID);[/code2]

-999
UnityEngine.MonoBehaviour:print(Object)


And when i stop the game:

Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: View (0)-999 on PlayerController(Clone) (scene). Not Destroying GameObject or PhotonViews!
UnityEngine.Debug:LogError(Object)


And i have no idea why my object is getting -999 viewid

Comments

  • I'm an idiot...
    It should be:
    [code2=csharp]void OnPhotonRandomJoinFailed ()
    {
    PhotonNetwork.CreateRoom (null);
    }

    void OnJoinedRoom()
    {
    SpawnMe();
    }[/code2]
  • The -999 means you instantiated something while not being in a Room.
    At the moment, PUN doesn't check this, so you can break it.

    The code you posted next should avoid the issue, right?