0

I am attempting to polish up a login and register script for a unity app. I've created a callback action delegate and I attempt to pass parameters in via a lambda expression. however, when it calls another function in the second script, i get a null reference exception.

this is how i pass it in. note that registerUser is the second script

if (checkPassword(password) && password == confirm)
        {
            registerUser.RegisterScene(email, password, user, (isSuccess, errorMsg) =>
            {
                if (isSuccess)
                {
                    Debug.Log(errorMsg);
                    StartCoroutine(errorMessage(errorMsg, Color.green, 3f));
                }

                if (!isSuccess)
                {
                    Debug.Log(errorMsg);
                    StartCoroutine(errorMessage(errorMsg, Color.red, 3f));
                }
            });
        }

and this is where i get the null reference exception.

public static void RegisterScene(string email, string password, string user, Action<bool, string> callback)
{
    _instance.registerAsync(email, password, user, callback);
}

i am unsure as to why i am getting this error so if anyone can clear this up for me that whould be great thanks!

EDIT: here is how i declare my singleton. i didnt make it thread safe or put anything fancy in it. i just want it to work

public Profile()
{

}

void start()
{
    Debug.Log(_instance);
    if (_instance == null)
    {
    _instance = new Profile();
    Debug.Log(_instance);
    }
}
Tengku Fathullah
  • 951
  • 1
  • 12
  • 38
Paul Kumar
  • 17
  • 1
  • 1
  • 8
  • yeah actually debugging that i found that is the problem. i am using singleton design and have a portion in it (if _instance == null){ _instance = this;} in the start() method. should i make its own method? – Paul Kumar Sep 15 '17 at 00:31
  • Profile() { } void start() { Debug.Log(_instance); if (_instance == null) { _instance = new Profile(); Debug.Log(_instance); } } – Paul Kumar Sep 15 '17 at 01:17
  • thats how i structure it. – Paul Kumar Sep 15 '17 at 01:18

0 Answers0