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
0
Question by Desination-X · Aug 07, 2014 at 02:22 PM · multiplayerphotonnullreferenceexceptionconnection

PhotonNetwork.ConnectUsingSettings("DevBuild6b") returns NullReferenceException

I have a main menu script that also routes to multiplayer. It was working fine, but then out of the blue it decided it should start giving me the error "NullReferenceException" for PhotonNetwork.ConnectUsingSettings("DevBuild6b")

Although I don't understand what could possibly be going wrong, I checked my code over and over, and there was still nothing that could cause it! Does anyone know why?

Here is my MainMenu script (also includes the connection stuff):

 using UnityEngine;
 using System.Collections;
 
 public class MainMenu : Photon.MonoBehaviour {
 
     public GUISkin skin;
 
     public MovieTexture menuVid;
 
     private bool settingsMenu;
     private bool graphicsMenu;
     private bool controlsMenu;
     private bool multiplayerMenu;
     private bool showStatus = false;
     private bool showDefault = true;
     private bool showRoomDetails;
     private bool hostMenu;
     private bool joinMenu;
     private bool showHostStatus = false;
     private bool justPinging = false;
     private bool fullscreenBoolean = false;
     
     public int maxPlayers = 6;
 
     RoomOptions newRoomOptions = new RoomOptions();
 
     //Temporary setting values
     private float meshTreeDistValue;
     private float foliageDistValue;
     private float detailDistanceValue;
 
     private string inputRoomName = "";
     private string status = "Idle";
     private string hostStatus = "Idle";
 
     void Start () {
         menuVid.Play();
         menuVid.loop = true;
 
         meshTreeDistValue = UserSettings.meshTreeDistance;
         foliageDistValue = UserSettings.foliageDistance;
         detailDistanceValue = UserSettings.detailDistance;
 
         if(UserSettings.fullscreen == 0){
             fullscreenBoolean = false;
         } else {
             fullscreenBoolean = true;
         }
     }
 
     void OnGUI () {
         GUI.Label(new Rect(5, 5, 200, 30), PlayerPrefs.GetInt("Fullscreen").ToString());
         GUI.Label(new Rect(5, 35, 200, 30), fullscreenBoolean.ToString());
         GUI.Label(new Rect(5, 65, 200, 30), UserSettings.fullscreen.ToString());
         GUI.Label(new Rect(5, 95, 200, 30), Screen.fullScreen.ToString());
         GUI.skin = skin;
         GUI.Box(new Rect (Screen.width /2 - 125, Screen.height - 60, 250, 50), "Music: Dark Frog by Kevin MacLeod");
         if(showDefault){
             if (GUI.Button (new Rect (Screen.width /2 - 415, 30, 200, 85), "Singleplayer")) {
                 PlayerPrefs.SetString("Room Name", "");
                 Application.LoadLevel(1);
             }
             if(GUI.Button (new Rect(Screen.width /2 - 205, 30, 200, 85), "Multiplayer")){
                 multiplayerMenu = true;
                 showDefault = false;
             }
             if(GUI.Button (new Rect (Screen.width /2 + 5, 30, 200, 85), "Options")){
                 showDefault = false;
                 settingsMenu = true;
             }
             if(GUI.Button (new Rect (Screen.width /2 + 215, 30, 200, 85), "Exit Game")){
                 Application.Quit ();
             }
         }
 
         if (settingsMenu) {
             if (GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 - 120, 200, 50), "Controls")) {
                 settingsMenu = false;
                 controlsMenu = true;
             } else if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 - 60, 200, 50), "Graphics")){
                 settingsMenu = false;
                 graphicsMenu = true;
             } else if(GUI.Button (new Rect(Screen.width /2 - 80, Screen.height /2 + 60, 160, 50), "Close")){
                 settingsMenu = false;
                 showDefault = true;
             }
         }
 
         if(graphicsMenu){
             if(GUI.Button (new Rect(Screen.width /2 - 475, Screen.height /2 - 60, 450, 50), "Shadows: " + UserSettings.shadows_statusText)){
                 if(UserSettings.shadows == 0){
                     GameObject scriptsObj = GameObject.Find("Camera");
                     UserSettings sun = scriptsObj.GetComponent<UserSettings>();
                     sun.setShadowMode(1);
                 } else if (UserSettings.shadows == 1){
                     GameObject scriptsObj = GameObject.Find("Camera");
                     UserSettings sun = scriptsObj.GetComponent<UserSettings>();
                     sun.setShadowMode(2);
                 } else if (UserSettings.shadows == 2){
                     GameObject scriptsObj = GameObject.Find("Camera");
                     UserSettings sun = scriptsObj.GetComponent<UserSettings>();
                     sun.setShadowMode(0);
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 475, Screen.height /2, 450, 50), "Texture Quality: " + UserSettings.textureQuality_statusText)){
                 if(UserSettings.textureQuality == 0){
                     UserSettings.setTextureQuality(1);
                 } else if (UserSettings.textureQuality == 1){
                     UserSettings.setTextureQuality(2);
                 } else if (UserSettings.textureQuality == 2){
                     UserSettings.setTextureQuality(3);
                 } else if (UserSettings.textureQuality == 3){
                     UserSettings.setTextureQuality(0);
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 475, Screen.height /2 + 60, 450, 50), "vSync: " + UserSettings.vSync_statusText)){
                 if(UserSettings.vSync == 0){
                     UserSettings.setVSync(1);
                 } else if (UserSettings.vSync == 1){
                     UserSettings.setVSync(0);
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 475, Screen.height /2 - 120, 450, 50), "Item Bobbing: " + UserSettings.itemBobbing_statusText)){
                 if(UserSettings.itemBobbing == 0){
                     UserSettings.setItemBobbing(1);
                 } else if (UserSettings.itemBobbing == 1){
                     UserSettings.setItemBobbing(0);
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 475, Screen.height /2 -180, 450, 50), "Screen resolution: " + UserSettings.resolutionX.ToString() + "x" + UserSettings.resolutionY.ToString())){
                 if(UserSettings.resolutionX == 1920){
                     UserSettings.setResolution(800, 600);
                 } else if (UserSettings.resolutionX == 800){
                     UserSettings.setResolution(1024, 768);
                 } else if (UserSettings.resolutionX == 1024){
                     UserSettings.setResolution(1360, 768);
                 } else if (UserSettings.resolutionX == 1360){
                     UserSettings.setResolution(1366, 768);
                 } else if (UserSettings.resolutionX == 1366){
                     UserSettings.setResolution(1920, 1080);
                 } else {
                     UserSettings.setResolution(Screen.width, Screen.height);
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 + 25, Screen.height /2 - 180, 450, 50), "Fullscreen: " + fullscreenBoolean.ToString())){
                 if(fullscreenBoolean == false){
                     fullscreenBoolean = true;
                     UserSettings.toggleFullscreen(fullscreenBoolean);
                 } else if(fullscreenBoolean == true){
                     fullscreenBoolean = false;
                     UserSettings.toggleFullscreen(fullscreenBoolean);
                 }
             }
             //Add new button above here
             
             //Sliders:
             GUI.Box(new Rect (Screen.width /2 + 25, Screen.height /2, 200, 25), "Mesh tree distance: " + UserSettings.meshTreeDistance.ToString("F0"));
             meshTreeDistValue = GUI.HorizontalSlider(new Rect (Screen.width /2 + 25, Screen.height /2 + 30, 200, 20), meshTreeDistValue, 5, 400);
             UserSettings.setMeshTreeDistance(meshTreeDistValue);
             
             GUI.Box(new Rect (Screen.width /2 + 25, Screen.height /2 - 120, 200, 25), "Foliage distance: " + UserSettings.foliageDistance.ToString("F0"));
             foliageDistValue = GUI.HorizontalSlider(new Rect (Screen.width /2 + 25, Screen.height /2 - 90, 200, 20), foliageDistValue, 0, 250);
             UserSettings.setFoliageDistance(foliageDistValue);
             
             GUI.Box(new Rect (Screen.width /2 + 25, Screen.height /2 - 60, 200, 25), "Detail distance: " + UserSettings.detailDistance.ToString("F0"));
             detailDistanceValue = GUI.HorizontalSlider(new Rect (Screen.width /2 + 25, Screen.height /2 - 30, 200, 20), detailDistanceValue, 5, 500);
             UserSettings.setDetailDistance(detailDistanceValue);
             
             //Add new slider above here
 
             //BACK FROM GRAPHICS MENU BUTTON
             if(GUI.Button (new Rect(Screen.width /2 - 60, Screen.height / 2 + 120, 120, 50), "Back")){
                 graphicsMenu = false;
                 settingsMenu = true;
             }
         }
 
         if(hostMenu && !showHostStatus){
             inputRoomName = GUI.TextField(new Rect(Screen.width /2 - 125, Screen.height /2 - 15, 250, 30), inputRoomName);
             if(inputRoomName.Length > 0){
                 if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 20, 200, 75), "Create room")){
                     Connect ();
                     showHostStatus = true;
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 105, 200, 75), "Back")){
                 hostMenu = false;
                 multiplayerMenu = true;
             }
         }
 
         if(hostMenu && showHostStatus){
             GUI.Box(new Rect (Screen.width /2 - 100, Screen.height /2 - 30, 200, 60), hostStatus);
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height - 100, 200, 30), "Cancel")){
                 PhotonNetwork.Disconnect();
                 showHostStatus = false;
             }
         }
 
         if(joinMenu && !showStatus){
             inputRoomName = GUI.TextField(new Rect (Screen.width /2 - 125, Screen.height /2 - 15, 250, 30), inputRoomName);
             if(inputRoomName.Length > 0){
                 if (GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 20, 200, 75), "Connect")){
                     Connect();
                     showStatus = true;
                     StartCoroutine(timeout (12));
                 }
             }
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 105, 200, 75), "Back")){
                 joinMenu = false;
                 multiplayerMenu = true;
             }
         }
 
         if(multiplayerMenu){
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 10, 200, 50), "Host")){
                 hostMenu = true;
                 multiplayerMenu = false;
             }
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 60, 200, 50), "Join")){
                 joinMenu = true;
                 multiplayerMenu = false;
             }
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height /2 + 180, 200, 50), "Back")){
                 multiplayerMenu = false;
                 showDefault = true;
             }
         }
 
         if (joinMenu && showStatus && !showRoomDetails){
             GUI.Box(new Rect (Screen.width /2 - 100, Screen.height /2 - 30, 200, 60), status);
             if(GUI.Button (new Rect(Screen.width /2 - 100, Screen.height - 100, 200, 30), "Cancel")){
                 PhotonNetwork.LeaveLobby();
                 PhotonNetwork.Disconnect();
                 showStatus = false;
             }
         }
 
         if(showRoomDetails){
             if(GUI.Button(new Rect( Screen.width /2 - 500, Screen.height /2 + 60, 200, 50), "Back")){
                 showRoomDetails = false;
                 showStatus = false;
                 PhotonNetwork.LeaveRoom();
                 PhotonNetwork.LeaveLobby();
                 PhotonNetwork.Disconnect();
             }
             if(GUI.Button(new Rect( Screen.width /2 + 300, Screen.height /2 + 60, 200, 50), "Join")){
                 PlayerPrefs.SetString("Room Name", inputRoomName);
                 PlayerPrefs.SetInt("HostOrClient", 0);
                 PlayerPrefs.Save ();
                 Application.LoadLevel(1);
             }
             GUI.Box (new Rect(Screen.width /2 - 500, Screen.height /2 - 250, 1000, 250), "Room found\n\n" + PhotonNetwork.room.name + "\nPlayer count: " + (PhotonNetwork.room.playerCount -1).ToString() + "/" + PhotonNetwork.room.maxPlayers.ToString());
         }
 
         if(controlsMenu){
             showDefault = true;
             controlsMenu = false;
         }
     }
 
     
     public void Connect (){
         status = "Connecting to master server...";
         hostStatus = "Connecting to master server...";
         PhotonNetwork.ConnectUsingSettings("DevBuild6b");
         PhotonNetwork.JoinLobby ();
         status = "Reaching network...";
         hostStatus = "Creating host...";
     }
 
     public void OnJoinedLobby () {
         if(joinMenu){
             PhotonNetwork.JoinRoom(inputRoomName);
             status = "Joining room: " + inputRoomName;
         }
         else if(hostMenu){
             //Let's ping with a server and see if it exists. If not, we create it.
             justPinging = true;
             PhotonNetwork.JoinRoom(inputRoomName);
             StartCoroutine(timeout(4));
         }
     }
 
     public void OnJoinedRoom (){
         if(joinMenu)
             showRoomDetails = true;
     }
 
     public void startHost () {
         PlayerPrefs.SetString("Room Name", inputRoomName);
         PlayerPrefs.SetInt("HostOrClient", 1);
         PlayerPrefs.Save ();
         Application.LoadLevel(1);
     }
 
     IEnumerator timeout (int i) {
         yield return new WaitForSeconds(5);
         if(!PhotonNetwork.inRoom && !justPinging){
             status = "Unable to connect:\nRoom doesn't exist / Server full";
             PhotonNetwork.LeaveLobby();
         }
         if(justPinging){
             if(PhotonNetwork.inRoom){
                 PhotonNetwork.LeaveRoom();
                 PhotonNetwork.LeaveLobby();
                 PhotonNetwork.Disconnect();
                 status = "There is already a room by that name! Please pick a different, unique room name.";
                 justPinging = false;
             } else {
                 justPinging = false;
                 newRoomOptions.maxPlayers = maxPlayers;
                 PhotonNetwork.CreateRoom(inputRoomName, newRoomOptions, TypedLobby.Default);
                 startHost();
             }
         }
     }
 
 }
 

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiplayer using Photon ?? 1 Answer

Photon Networking - What function(s) are called when a player (not me) is spawned? 2 Answers

Photon scene objects not players! 1 Answer

Unity photon network - game room 1 Answer

Sending (and receiving) player names with Photon Networking 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