- Home /
Photon Instantiate doesn't always work
I am trying to make a multiplayer game using photon networking. In my code i try using PhotonNetworking.Instantiate to instatiate a player in first person. Sometimes it instatiates , and sometimes it doesn't. How can i make it ALWAYS instantiate a player(deterministic)?
Here is my code
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour
{
public Camera standbyCamera;
PlayerSpot[] spots;
// Use this for initialization
void Start()
{
spots = GameObject.FindObjectsOfType<PlayerSpot>();
foreach (PlayerSpot ss in spots)
Debug.Log("Position " + ss.transform.position + "And rotation " + ss.transform.rotation);
Connect();
}
/*
// Update is called once per frame
void Update () {
}
*/
void Connect()
{
//PhotonNetwork.ConnectToMaster there is no photonnetwork.connect
PhotonNetwork.ConnectUsingSettings("FPS D.S 1.0");
}
// VELIKO O na pocetku
void OnJoinedLobby()
{
//PhotonNetwork.JoinOrCreateRoom we could use this
PhotonNetwork.JoinRandomRoom();
}
void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
void OnPhotonRandomJoinFailed()
{
//Debug.Log();
PhotonNetwork.CreateRoom(null);
}
//http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo#_Toc317517589
void OnJoinedRoom()
{
Debug.Log("OnJoinedRoom");
standbyCamera.enabled = false;
PlayerSpot ss = spots[Random.Range(0, spots.Length)];
//Quaternion unity google = http://docs.unity3d.com/ScriptReference/Quaternion.html
Debug.Log("player info\n"+ss.transform.transform.name+" Position " + ss.transform.position + "And rotation " + ss.transform.rotation);
GameObject myPlayer= PhotonNetwork.Instantiate("Mujo", ss.transform.position, ss.transform.rotation, ss.teamID);
Debug.Log("PhotonInstantiate in onjoinedroom");
//Instantiate(playerPrefab) just creates on our own pc not every one who is connected
}
}
Here it is instantiating (and me moving it backwards a bit)
And here it is not instantiating (you can see the console and the logs the block completes)
How can i make it work ?
I am using 4.5.5f1 unity and my mesh ground and building are made in blender 2.72.
Solved!
The solution was to add PhotonNetwork.networkingPeer.SetReceivingEnabled (1, true); since groups need to be preregistered by the NetwokringPeer class and its hashtables
Your answer
Follow this Question
Related Questions
Photon animation issue 0 Answers
A node in a childnode? 1 Answer
Photon unity issues 2 Answers
PhotonNetworking Colliders of players dont collide 0 Answers