- Home /
PUN is being incredibly slow in builds
Hello! I'm currently creating a very simple pong clone with multiplayer, every aspect of the game works fine except for the multiplayer part. Creating a room and everything is fine in the editor, but as soon as I make a build and run it everything is 20 times slower, and it doesn't even seem to be able to create a room. And my internet stops working aswell, when i try the build.
I don't know if this code is even close to correct (I would appreciate help with that to)
using UnityEngine;
using System.Collections;
public class ConnectRandom : MonoBehaviour {
// Use this for initialization
public float spawnpos;
string curstage;
private const string roomName = "Room";
RoomInfo[] roominfo;
private void Awake(){
PhotonNetwork.logLevel = PhotonLogLevel.Full;
Debug.Log("Awake!");
if(!PhotonNetwork.connected){
PhotonNetwork.ConnectUsingSettings("1.0");
curstage = "Connecting...";
Debug.Log("Connecting...");
}
}
void OnJoinedLobby(){
Debug.Log("Joined the Lobby...");
// JoinGame ();
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log("Couldn't join a random room");
curstage = "Random join failed";
RoomInfo[] rinfo = PhotonNetwork.GetRoomList();
for(int i = 0; i < rinfo.Length; i++)
Debug.Log(rinfo[0]);
curstage = "Creating a room";
Debug.Log("Creating a room!");
PhotonNetwork.CreateRoom(null); // Doesn't move past this point as far as I can tell
}
void OnPhotonCreateGameFailed(){
curstage = "Failed to create game";
Debug.Log("Failed to create a game!");
}
void OnJoinedRoom(){
if(PhotonNetwork.isMasterClient)
PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable(){{"ScoreServer", 0}, {"ScoreClient", 0}});
if(PhotonNetwork.isMasterClient)
spawnpos *= -1f;
Vector3 spawnvec = new Vector3(spawnpos, 0f, 0f);
GameObject go = (GameObject)PhotonNetwork.Instantiate("Playerone", spawnvec, Quaternion.identity, 0);
go.GetComponent<Paddlemove>().enabled = true;
Debug.Log ("Joined a Game!");
curstage = "Joined game";
Debug.Log((int)PhotonNetwork.room.customProperties["ScoreServer"] + " " + (int)PhotonNetwork.room.customProperties["ScoreClient"]);
}
void OnCreateRoom(){
curstage = "Created a room";
Debug.Log("Created a Room!");
}
void OnGUI(){
GUI.Label(new Rect(0f,0f,100f,20f), curstage);
}
}
The code looks ok but you do an awful lot of logging (PhotonNetwork.logLevel = PhotonLogLevel.Full). You will need to make use of the log to see what slows you down. I don't think it's this code.
Answer by HonoraryBob · Jul 06, 2015 at 03:22 PM
I think the thing that's slowing it down is the heavy use of Debug.Log, which is very slow and sometimes will cripple program execution. When one of my scripts used Debug.Log only once each frame, it slowed the entire game down to a crawl and clipped sound effects so they sounded tinny and distorted.
Your answer
Follow this Question
Related Questions
How To Destroy An Object Server Side When Using OnTriggerEnter 1 Answer
PUN - Choose random Hero for player 0 Answers
How to connect to our own dedicated server using photon networking in unity?(Self-hosted) 0 Answers
Is that any way to pass list of array through photon? 0 Answers
Code Wont Work? 0 Answers