Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by Paulk33 · Aug 11, 2017 at 06:51 AM · referencingnull reference exceptionreference-other-objectnull reference

null reference help. i fundamentally dont understand.

when trying to build my menu screen, i keep recieving null reference exceptions. it occurs when i press one of the two buttons on my screen. the two buttons controller whether im trying to register or log in. here is my code: i get the errors at mainmenu line 62 and login line 37

Main Menu Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class MainMenu : MonoBehaviour {
 
     private Register register;
     private LogIn login;
     public Button openRegister, openLog, registerButton, LoginButton;
     public InputField email, password, newEmail, newPassword, confirm;
     public GameObject game;
     
     private string em, pass, newEm, newPass, conf;
 
     //leave the error texts and stuff for now
 
 
 
     // Use this for initialization
     void Start () {
         Register register = game.GetComponent<Register>();
         LogIn login = game.GetComponent<LogIn>();
 
         //set the buttons from the log and register scripts
         login.initButtons();
         register.initButtons();
 
         
     }
     
     // Update is called once per frame
     void Update () {
         em = email.text;
         pass = password.text;
         newEm = newEmail.text;
         newPass = password.text;
         conf = confirm.text;
 
         openLog.onClick.AddListener(openLogClick);
         openRegister.onClick.AddListener(openRegisterClick);
     }
     
     void setStrings()
     {
         em = email.text;
         pass = password.text;
         newEm = newEmail.text;
         newPass = password.text;
         conf = confirm.text;
     }
 
     void openLogClick()
     {
         login = new LogIn();
         login.logIn(em, pass);
     }
 
     void openRegisterClick()
     {
 
         register.registerUser(newEm, newPass, conf);
     }
 }
 

Login Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using Firebase.Auth;
 using UnityEngine.SceneManagement;
 
 
 public class LogIn : MonoBehaviour {
 
     public InputField emailIn, passwordIn;
     public Button signInButton, openLogIn;
     public Text emailErrorText, passwordErrorText, successText;
     public GameObject eI, pI, sIButton, oLButton;
 
     private string emailString, passwordString;
     private FirebaseAuth auth;
     private bool userWantsLog = false , isButton = false;
 
     private Register checkUser;
     private Users user;
 
     private void Start()
     {
         emailErrorText.text = "";
         passwordErrorText.text = "";
         Register checkUser = GetComponent<Register>();
         Users user = GetComponent<Users>();
         initButtons();
 
         auth = FirebaseAuth.DefaultInstance;
 
     }
 
     public void logIn(string email, string password)
     {
         if(checkUser.UserChecker(email, password))
         {
             SceneManager.LoadScene(1);
         }
     }
 
     public void setAcctive()
     {
         eI.SetActive(true);
         pI.SetActive(true);
         sIButton.SetActive(true);
         oLButton.SetActive(false);
     }
 
     public void initButtons()
     {
         eI.SetActive(false);
         pI.SetActive(false);
         sIButton.SetActive(false);
         oLButton.SetActive(true);
 
     }
 
     void getStrings()
     {
         emailString = emailIn.text;
         passwordString = passwordIn.text;
     }
 
     void clickEvent()
     {
         isButton = true;
     }
     
     void openLogClick()
     {
         userWantsLog = true;
     }
 
     void log(string email, string password) {
 
         auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
             if (task.IsCanceled)
             {
                 Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
                 return;
             }
             if (task.IsFaulted)
             {
                 Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                 return;
             }
 
             Firebase.Auth.FirebaseUser newUser = task.Result;
             Debug.LogFormat("User signed in successfully: {0} ({1})",
                 newUser.DisplayName, newUser.UserId);
         });
     }
 }
 

Register Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 using Firebase.Unity.Editor;
 using UnityEngine.UI;
 using Firebase.Auth;
 using System.Linq;
 using UnityEngine.SceneManagement;
 
 public class Register : MonoBehaviour
 {
 
     public InputField Password, Email, Confirm;
     public Text success, errorText;
     public Button registerButton, openRegister;
     public GameObject nEM, nP, nCP, SU, registerObject;
 
     private Scene scene;
     private string email, password, conf;
     private bool successToken = false;
     private bool isRegister;
     private int userCount;
 
     private Users user;
     private FirebaseAuth auth;
     private SceneChanger change;
     private Users[] userArray;
     Scene currentScene;
 
     // Use this for initialization
     void Start()
 
     {
         isRegister = false;
         
         change = GetComponent<SceneChanger>();
         currentScene = SceneManager.GetActiveScene();
 
         userCount = 0;
         
         userArray = new Users[100];
        
         auth = FirebaseAuth.DefaultInstance;
         
         success.text = "";
         errorText.text = "";
     }
 
     public void registerUser(string email, string password, string confirm)
     {
         this.email = email;
         this.password = password;
         conf = confirm;
 
 
         //check whether the password meets criteria and whether they match
         checkPass();
         checkConfirm();
 
         if(checkPass() && checkConfirm())
         {
             if (UserChecker(this.email, this.password))
             {
                 addUser();
             }
         }
     }
 
     void setActive()
     {
         nEM.SetActive(true);
         nP.SetActive(true);
         nCP.SetActive(true);
         SU.SetActive(true);
         
     }
 
     public void initButtons()
     {
         nEM.SetActive(false);
         nP.SetActive(false);
         nCP.SetActive(false);
         SU.SetActive(false);
         registerObject.SetActive(true);
     }
 
     bool checkConfirm()
     {
         if (conf == password)
             return true;
         else
             return false;
     }
 
     bool checkPass()
     {
         if (password.Length >= 6 && password.Any(char.IsUpper) && password.Any(char.IsDigit)){
             return true;
         }
 
         else return false;
     }
 
     bool registerSuccessToken()
     {
         if (checkConfirm() && checkPass())
             return true;
         return false;
     }
     
     void signUp(string email, string password)
     {
 
         auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
             if (task.IsCanceled)
             {
                 Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
                 return;
             }
             if (task.IsFaulted)
             {
                 Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                 return;
             }
 
             // Firebase user has been created.
             Firebase.Auth.FirebaseUser newUser = task.Result;
             successToken = true;
             Debug.LogFormat("Firebase user created successfully: {0} ({1})",
                 newUser.DisplayName, newUser.UserId);
         });
         
     }
 
     void addUser()
     {
         user = new Users(email, password);
         userArray[userCount] = user;
         userCount++;
 
         Debug.Log(user.retEmail());
         Debug.Log("if there arent");
     }
 
 
     void registerB()
     {
         isRegister = true;
         nEM.SetActive(true);
         nP.SetActive(true);
         nCP.SetActive(true);
         SU.SetActive(true);
         registerObject.SetActive(false);
     }
     
     void singUpClicked()
     {
         Debug.Log("enters if. creating user");
         signUp(email, password);
         isRegister = false;
         setActive();
         registerObject.SetActive(true);
 
         addUser();
     }
     
     public bool UserChecker(string em, string pass)
     {
         //string emailHold, passHold;
         if (userArray.Length == 0)
         {
             errorText.text = "no users exist";
             return true;
         }
 
         else
         {
             for (int i = 0; i < userArray.Length; i++)
             {
                 Debug.Log(userArray[i].retEmail());
                 Debug.Log(userArray[i].retPass());
                 if (userArray[i].retEmail() == em && userArray[i].retPass() == pass)
                     return true;
             }
             return false;
         }
     }
 }

someone please help. i do not fundamentally get how to reference the other scripts.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Frederikw · Apr 06, 2020 at 08:47 PM

I know its an old question, but I have the exact same problem. Any solutions?

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

68 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

#Need Fast Help# NullReferenceException: Object reference not set to an instance of an object 0 Answers

Any other ways for instantiated prefabs to reference game-objects in the scene? 0 Answers

How do I reference an Instantiate object? 1 Answer

"NullReferenceException: Object reference not set to an instance of an object GameHelper.Update () (at Assets/Scripts/GameHelper.cs:44)" 2 Answers

Access variables or methods from another class (or gameObject) [C#] 1 Answer


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