Search Unity

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:
    4,545
    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

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,426
    WHICH debug was printing out?
     
    Tim-Duval 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:
    4
    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:
    1,658
    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:
    5,494
    I'd probably just set some bool which you can check in Update, and change scenes there if the bool is set true.
     
    xVergilx likes this.