Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Photon Network Instantiate Problem

Discussion in 'Multiplayer' started by tookydo, Aug 17, 2014.

  1. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    I am making a multiplayer game and I have the code to connect to the server and join a room and all that. But when I try to do "PhotonNetwork.Instansiate("Seeker", Vector3.zero, Quaternion.identity, 0);" It just says failed to instantiate prefab "Seeker". It doesn't tell me why, just that it failed to do so. How do I fix this?
     
  2. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    Please copy-paste full error message here.
    I see at least 3 error messages in PhotonNetwork.Instantiate() method . All with failure descriptions.
     
  3. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    Here is the error:

    Failed to Instantiate prefab: Seeker. Client should be in a room. Current connectionStateDetailed: PeerCreated
    UnityEngine.Debug:LogError(Object)
    PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32, Object[]) (at Assets/Plugins/PhotonNetwork/PhotonNetwork.cs:2026)
    PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32) (at Assets/Plugins/PhotonNetwork/PhotonNetwork.cs:2009)
    OnGameStart:Start() (at Assets/My Resources/Scripts/Networking/OnGameStart.cs:6)

    Here is the code:

    using UnityEngine;
    using System.Collections;

    public class OnGameStart : MonoBehaviour {
    void Start () {
    PhotonNetwork.Instantiate ("Seeker", new Vector3(333.043f, 23.18f, 203.783f), Quaternion.identity, 0);
    }
    }
    @vadiml

    I was using javascript first but photon doesn't like javascript for some reason so I just used csharp.
     
    Last edited: Aug 18, 2014
  4. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    The message states failure reason very clearly: "Client should be in a room. Current connectionStateDetailed: PeerCreated".
    Join room first and move PhotonNetwork.Instantiate() call from Start() to OnJoinedRoom().
     
  5. LlamaWaffles555

    LlamaWaffles555

    Joined:
    Sep 30, 2015
    Posts:
    11
    I did that but im still getting this error
     
  6. SingMoon

    SingMoon

    Joined:
    Apr 15, 2017
    Posts:
    1
    IEnumerator StartAsync(){
    PhotonNetwork.ConnectUsingSettings(Version + "." + SceneManagerHelper.ActiveSceneBuildIndex);
    PhotonNetwork.automaticallySyncScene = true;

    if (string.IsNullOrEmpty(PhotonNetwork.playerName))
    {
    PhotonNetwork.playerName = "Guest" + Random.Range(1, 9999);
    }
    Debug.Log ("开始链接网络");
    while (!PhotonNetwork.connected) {
    yield return 0;
    }
    Debug.Log ("已链接网络,准备进入大厅");
    while (!PhotonNetwork.insideLobby) {
    yield return 0;
    }
    Debug.Log ("已进入大厅,准备进入房间");
    RoomInfo[] RoomInfos = PhotonNetwork.GetRoomList ();

    if (RoomInfos.Length > 0) {
    bool isEnter = false;
    for (int i = 0; i < RoomInfos.Length; i++) {
    if (RoomInfos .PlayerCount < maxPlayerCount) {
    if (PhotonNetwork.JoinRoom (RoomInfos .Name)) {
    Debug.Log ("进入已有房间");
    isEnter = true;
    break;
    }
    }
    }
    if (!isEnter) {
    int RoomNum = int.Parse (RoomInfos [RoomInfos.Length - 1].Name.Substring (4)) + 1;
    PhotonNetwork.CreateRoom ("Room" + RoomNum, new RoomOptions () { MaxPlayers = maxPlayerCount}, null);
    }
    } else {
    PhotonNetwork.CreateRoom ("Room0", new RoomOptions() { MaxPlayers = maxPlayerCount}, null);
    }
    while (!PhotonNetwork.inRoom) {
    yield return 0;
    }
    Debug.Log ("已进房间,准备创建用户");
    GameObject userPlayer = PhotonNetwork.Instantiate ("NetPlayer", transform.position, transform.rotation, 0);
    netPlayer = userPlayer.GetComponent<MnNetPlayerProperty> ();

    }