Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cannot load scene

Discussion in 'Scripting' started by ychriisli, Jan 30, 2019.

  1. ychriisli

    ychriisli

    Joined:
    Dec 29, 2018
    Posts:
    4
    Hi, i am building a game with firebase as a backend for authentication..
    But, Why i cannot load my scene (1) with my script

    I already attached button etc

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Firebase;
    5. using Firebase.Auth;
    6. using System.Threading.Tasks;
    7. using UnityEngine.SceneManagement;
    8.  
    9.  
    10. public class AuthManager : MonoBehaviour
    11. {
    12.     // Firebase variable API
    13.     Firebase.Auth.FirebaseAuth auth;
    14.  
    15.     //Delegates
    16.     public delegate IEnumerator AuthCallback(Task<Firebase.Auth.FirebaseUser> task, string operation);
    17.     public event AuthCallback authCallBack;
    18.  
    19.  
    20.  
    21.  
    22.     void Start()
    23.     {
    24.    
    25.         auth = FirebaseAuth.DefaultInstance;
    26.    
    27.  
    28.     }
    29.  
    30.     public void SignUpNewUser(string email, string password)
    31.     {
    32.         auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task =>
    33.          {
    34.              if ( task.IsFaulted || task.IsCanceled)
    35.              {
    36.                  Debug.Log("Not working cz" + task.Exception);
    37.              }
    38.              if (task.IsCompleted)
    39.              {
    40.              
    41.              
    42.                  Debug.Log("test");
    43.                  SceneManager.LoadScene(1);
    44.  
    45.              }
    46.          });
    47.     }
    and iam using Form Manager

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using System.Text;
    6. using System.Text.RegularExpressions;
    7. using System.Threading.Tasks;
    8. using Firebase;
    9. using Firebase.Auth;
    10. using UnityEngine.SceneManagement;
    11.  
    12. public class FormManager : MonoBehaviour
    13. {
    14.     public InputField emailInput;
    15.     public InputField passwordInput;
    16.  
    17.     public Button signUpButton;
    18.     public Button loginButton;
    19.  
    20.     public Text statusText;
    21.  
    22.     public AuthManager authManager;
    23.  
    24.     void Start()
    25.     {
    26.         // Auth delegate subscriptions
    27.        // authManager.authCallBack += handleAuthCallBack;
    28.  
    29.     }
    30.  
    31.  
    32.     public void ValidateEmail()
    33.     {
    34.         string email = emailInput.text;
    35.  
    36.     }
    37.  
    38.  
    39.  
    40.     public void OnSignUp()
    41.     {
    42.         authManager.SignUpNewUser(emailInput.text, passwordInput.text);
    43.         Debug.Log("sign up");
    44.     }
    [/code]
     
    Last edited: Jan 30, 2019
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    Is the debug printing out? Are you getting errors? Do you have the scenes added into your build settings?

    Also, use code tags next time, it will help people help you.
     
  3. ychriisli

    ychriisli

    Joined:
    Dec 29, 2018
    Posts:
    4
    The debug was printing out, every scene were added in build setting and i got no error..
     
    Last edited: Jan 30, 2019
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    WHICH debug was printing out?
     
    MisterSkitz likes this.
  5. ychriisli

    ychriisli

    Joined:
    Dec 29, 2018
    Posts:
    4
    This debug

    Code (CSharp):
    1. if (task.IsCompleted)
    2.              {
    3.            
    4.            
    5.                  Debug.Log("test");
    6.                  SceneManager.LoadScene(1);
     
    Eelcapitan likes this.
  6. Eelcapitan

    Eelcapitan

    Joined:
    Dec 1, 2015
    Posts:
    5
    I have exactly the same issue. SceneManager.LoadScene() does not work within an "if (task.IsCompleted) " if function, and does not work within the task itself.
     
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I think its because Firebase is actually is running on the separate thread.
    Try calling that method from the main thread instead.
     
  8. zehidu

    zehidu

    Joined:
    Jun 14, 2019
    Posts:
    1
    exactly the same problem, so where can i find that main thread?
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd probably just set some bool which you can check in Update, and change scenes there if the bool is set true.
     
  10. bhongleram

    bhongleram

    Joined:
    Oct 3, 2019
    Posts:
    2

    Thanx man..this worked for me.
     
    HeLinChooi likes this.
  11. Deepankar_gupta

    Deepankar_gupta

    Joined:
    Oct 13, 2020
    Posts:
    1
    Thanks man you saved my day.
     
  12. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    There is no longer a need for a bool. Firebase has newer versions of their sdk that have a new way to continue.

    Code (CSharp):
    1.        
    2. auth.SignInWithEmailAndPasswordAsync(email, pword).ContinueWithOnMainThread(task =>
    3. {
    4.     if(task.IsCanceled)
    5.     {
    6.  
    7.     }
    8.     if (task.IsFaulted)
    9.     {
    10.  
    11.     }
    12.     if(task.IsCompleted)
    13.     {
    14.     }
    15. });
    The new call allows it to return to the main thread when done.
     
    NGC6720 likes this.