Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by TritZium · Jan 03, 2015 at 06:10 PM · c#multiplayerphotonmultiplayer-networking

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);
         }
     }
     
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tobiass · Jan 12, 2015 at 10:00 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges