Unity editor version: 20183.6f1
Firebase Unity SDK version: 5.4.4
Additional SDKs you are using (Facebook, AdMob, etc.):
Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows
Platform you are targeting (iOS, Android, and/or desktop): Android
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;
Debug.LogFormat("Firebase user created successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
SceneManager.LoadScene("Login"); // *does not execute codes in this part *
titulo.text = user.DisplayName; // *does not execute codes in this part *
});
because I can not execute tasks in this part of the script, so as to perform the email registration it will follow for a new task, I have difficulties, everything that text inside does not work
I'm already tired, days trying.
The likely cause is that the code in the ContinueWith is not run on the Unity main thread. You can either make the callback happen on the main thread (this GitHub issue thread can help: https://github.com/firebase/quickstart-unity/issues/261), or you can set a flag in the ContinueWith, and in a MonoBehaviour's Update() call check for that flag, and do the LoadScene from there.
return auth.CreateUserWithEmailAndPasswordAsync(userLogin.email, userLogin.password)
.ContinueWith((task) => {
return RunOnMainThread(HandleCreateUser(task));
});
I'm sorry for the amateur questions, but how do I use this final call?
I create a function with this name HandleCreateUser (task)?
inside () what component do I put in this created function?
within this function, are the functions I want to be performed in conjunction with the creation of emails?
It is very important that I can solve this issue.
You could either add it inline, like
auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith((task) => {
return RunOnMainThread(() => {
// Add functions to call, like SceneManager.LoadScene(...)
});
});
or add it to a class as a function, and pass it along as shown in that other post.
What library is this code in?
RunOnMainThread
I could not find it in mine, I used it here
using System.Threading.Tasks;
I just found Task.Run ();
and if it is the same, I am still facing the Problem.
What happens is that I need to detect when there has been an Error or cancellation of the Cadastre to take action on this.
If the User uses a wrong email or password, how can I return an action, where can I receive this information?
All that is used in conjunction with an Error, task.IsFaulted, hangs the App.
Sorry @H4rdG4m3, the RunOnMainThread() @a-maurice was referring to is described here.
The likely cause is that the code in the ContinueWith is not run on the Unity main thread. You can either make the callback happen on the main thread (this GitHub issue thread can help: #261), or you can set a flag in the ContinueWith, and in a MonoBehaviour's Update() call check for that flag, and do the LoadScene from there.
Oh man, I've been searching this issue for some days now, you really helped me out, cheers!
Hi @H4rdG4m3, would like to double check if your issue has been resolved.
Hi, as you said you are somewhat of an amateur, and the solution they provided you can get a bit overcomplex. A way easier (and quicker) workaround for making the "ContinueWith" function run in the main thread (so it can execute "Unity code", is like this:
auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
// Whatever code you have here to check if the creation of the user failed or succeded
}, TaskScheduler.FromCurrentSynchronizationContext());
So, basically, add the "TaskScheduler.FromCurrentSynchronizationContext()" as a second parameter to the "ContinueWith" function, and it will make it run in the main thread. This way, things like "LoadScene" will work inside Firebase functions.
Hope you can implement it and it's useful to you.
TonyaGitHub you are wonderuful. I had the same issue, and I did not get how to write into the Main Thread. Your solution works like charm. Thank you so much, people like you make the world better, at least mine.
Wuhuuuuu..... :D
Since we haven't heard from anyone on this thread for a while we're closing this out.
TaskScheduler.FromCurrentSynchronizationContext());
Please full code
Most helpful comment
TonyaGitHub you are wonderuful. I had the same issue, and I did not get how to write into the Main Thread. Your solution works like charm. Thank you so much, people like you make the world better, at least mine.
Wuhuuuuu..... :D