- Home /
The question is answered, right answer was accepted
StartCouroutine is not working
This log is showing. But nothing is working after that.
Debug.Log("Creating Player" + ludoPlayerUser);
StartCoroutine(RegisterToSql(ludoPlayerUser));
here is the code in IEnumerator RegisterToSql(LudoPlayerUser ludoplayer). I thought there is a problem in UnityWebRequest() then I commented other codes and saw no debug log is showing. I am using Unity 2021.1.5f1
Debug.Log("Transferring to Sql");
/*WWWForm form = new WWWForm();
form.AddField("playerName", ludoPlayer.getPlayerName());
form.AddField("uid", ludoPlayer.getUid());
form.AddField("goldCoin", ludoPlayer.getGoldCoin());
form.AddField("contact", ludoPlayer.getContact());
form.AddField("diamondCoin", ludoPlayer.getDiamondCoin());
form.AddField("totalKill", ludoPlayer.getTotalKill());
form.AddField("photoUrl", ludoPlayer.getPhotoUrl());
Debug.Log("Form Created");
Debug.Log("Form: " + form);*/
yield return new WaitForSeconds(2);
That code is fine. What is the code around StartCoroutine()
, what is happening before it's called?
It authenticate users via firebase. when authentication is successful then I am creating user in database.
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);
LudoPlayerUser ludoPlayerUser = new LudoPlayerUser(newUser.Email, newUser.Email, 5000, 0, 0, newUser.UserId, null);
Debug.Log("Creating Player" + ludoPlayerUser);
StartCoroutine(RegisterToSql(ludoPlayerUser));
toast.showToast("Signup successful...", 2);
});
It would appear that the authentication task is not allowing for a Coroutine to run alongside it. It is really the only explanation I can come up with that accounts for the Log being run before it. That said, is it possible to run the Coroutine after the task completes or is it a necessity that it runs inside? Could you use a regular method as opposed to a Coroutine?
I think u have to put RegisterToSql(ludoPlayerUser)
just after yield return new WaitForSeconds(2);
Do you mean something like this? Debug.Log("Creating Player" + ludoPlayerUser); yield return new WaitForSeconds(2); StartCoroutine(RegisterToSql(ludoPlayerUser));
Follow this Question
Related Questions
I'd like to move a cube without delay.(C#) 0 Answers
StartCorutine not Working 3 Answers
Cannot null Coroutine variable if it calls an interface 2 Answers
How to begin startcoroutine (IEnumerator) with UI button. 1 Answer
WWW DownloadManager, C# 1 Answer