Search Unity

Third Party Photon Networking (PUN) Instantiated players cannot see previously instantiated players

Discussion in 'Multiplayer' started by sniperguy124, Nov 22, 2016.

  1. sniperguy124

    sniperguy124

    Joined:
    Aug 30, 2016
    Posts:
    1
    Hi.
    I am trying to make a multiplayer game in PUN, and it was going well until now. I have an issue when trying to instantiate players. I do use PhotonNetworking.Instantiate, but for some reason, when someone joins the scene the newly joined player cannot see the first player, but the first player can see the new player. I also get the warning:

    Received OnSerialization for view ID 1001. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined

    I have 2 scenes; one called LobbyMenu and another called Game.

    The script in the lobby:

    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;

    public class Launcher : Photon.MonoBehaviour
    {
    const string VERSION = "1";
    public string roomName = "iskrem";
    public string playerName;
    public Text input;
    public Text nameInput;
    public GameObject connect;
    public GameObject roomInfo;
    public GameObject NameInput;

    void Start()
    {
    PhotonNetwork.ConnectUsingSettings(VERSION);
    roomInfo.SetActive(false);
    NameInput.SetActive(false);
    connect.SetActive(true);
    }

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

    public void ConnectToRoom()
    {
    roomName = input.text;
    OnJoinedLobby();
    }

    public void Spawn()
    {
    PhotonNetwork.isMessageQueueRunning = false;
    PhotonNetwork.LoadLevel(1);
    }

    void OnLevelWasLoaded(int level)
    {
    PhotonNetwork.isMessageQueueRunning = true;
    }

    public void NameSelected()
    {
    playerName = nameInput.text;
    roomInfo.SetActive(true);
    NameInput.SetActive(false);
    }

    void OnJoinedLobby()
    {
    RoomOptions roomOptions = new RoomOptions() { IsVisible = false, MaxPlayers = 4 };
    PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
    print("Successfully Joined or Created" + roomName);
    }

    void OnJoinedRoom()
    {
    NameInput.SetActive(true);
    connect.SetActive(false);
    }
    }

    I also have a GameManager script witch is in the Game scene:
    using UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;

    public class GameManager : Photon.MonoBehaviour {

    public string playerPrefabName = "FPSController";
    public Transform SpawnPoint;

    void Start()
    {
    PhotonNetwork.automaticallySyncScene = true;
    PhotonNetwork.Instantiate(playerPrefabName, SpawnPoint.position, SpawnPoint.rotation, 0);
    }

    public void OnLeftRoom()
    {
    SceneManager.LoadScene(0);
    }

    public void LeaveRoom()
    {
    PhotonNetwork.LeaveRoom();
    }

    }


    Please help me.
     
  2. romatallinn

    romatallinn

    Joined:
    Dec 26, 2015
    Posts:
    161
    I usually Instantiate player in OnJoinedRoom. I am not sure it will work, but try.
     
    RecinoStudios and Munchy2007 like this.
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Unity usually deletes all GOs from one scene, when you load another.
    Depending on your timing, you might get the Instantiate message right before the command to load a scene.
    I didn't dig into your code but I hope this gives you a pointer to solve it.
     
  4. RecinoStudios

    RecinoStudios

    Joined:
    May 5, 2019
    Posts:
    1
    Thank you very much, that worked for me.
     
    tobiass likes this.