- Home /
I am using Photon my game player object does not appear in the scene
I am trying to create a Demo scene where basically there is a sphere game object with the name "SferaMortii". Through input from keyboard, that object only moves around. That is all it has to do and I am trying to make a multiplayer version in order for me to get used to Photon.
I have followed a tutorial that told me to attach a PhotonView Script to the player prefab, I have made a Resources Folder and inside I have moved the prefab, I have made a NetworkManager scrpt where I described the room options,etc. and then I used the Photon.Instantiate function.
I have followed all the steps and when running the game, the object doesn't instantiate and moreover I get this error:
SwitchToProtocol: Udp PhotonNetwork.connected: False UnityEngine.Debug:Log(Object) PhotonNetwork:SwitchToProtocol(ConnectionProtocol) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1172) PhotonNetwork:ConnectUsingSettings(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1219) NetworkManager:Start() (at Assets/Scripts/Network/NetworkManager.cs:12)
My script for the NetworkManager is the following:
using UnityEngine; using System.Collections;
public class NetworkManager : MonoBehaviour {
const string VERSION="v0.0.1";
public string roomName="MyRoom";
public string playerPrefabName="SferaMortii";
public Transform spawnPoint;
void Start () {
PhotonNetwork.ConnectUsingSettings (VERSION);
}
void OnJoinedLobby()
{
RoomOptions roomOptions = new RoomOptions (){ IsVisible = false, MaxPlayers = 4 };
PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default);
PhotonNetwork.Instantiate (playerPrefabName,
spawnPoint.position,
spawnPoint.rotation,
0);
}
void OnJoinedRoom()
{
PhotonNetwork.Instantiate (playerPrefabName,
spawnPoint.position,
spawnPoint.rotation,
0);
}
}
Should you have any useful advice or any observations, please help troubleshoot the problem!
remove line 16: you don't network instantiate in a lobby, only when you have connected to a room. The only purpose of the lobby is to find a room to join, or to create a room.
Answer by ChristianSimon · Sep 12, 2016 at 08:12 AM
Hi Nodgorod,
please make sure, that OnJoinedLobby()
and OnJoinedRoom()
are called during connection process. If they are not called, you might set PhotonNetwork.autoJoinLobby = true;
at the beginning of your Start() function or check the 'Auto-Join Lobby' option in the PhotonServerSettings file. Otherwise you need to join the lobby manually.
remove line 16: you don't network instantiate in a lobby, only when you have connected to a room. The only purpose of the lobby is to find a room to join, or to create a room.
Please take a look at that, too.
Your answer
Follow this Question
Related Questions
How to add a component to a prefab 1 Answer
Photon Networking Instantiating Problem 0 Answers
Instantiating player when creating a new room in photon not working. 0 Answers
PUN 2 : Impossible to applied damage to all player in overlapSphere created by a bomb ? 0 Answers
trying to catch photonNetwork instantiated object of another user 0 Answers