- Home /
Can't activate game object.
I cant find a way to activate my authentication error panel to display the error. print functions works fine, authError.text works fine. no errors shown in the console. authErrorPanel is assigned in the inspector.
switch (error)
{
case "Firebase.FirebaseException: An email address must be provided.":
print("no email");
authError.text = "Enter Email Address";
auhErrorPanel.SetActive(true);
break;
I think you might be looking for this method ins$$anonymous$$d of SetActive: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
Answer by Ironstone · Aug 08, 2019 at 04:24 PM
if your text gets changed correctly, perhaps you are activating the wrong gameObject? If you set the auhErrorPanel active, the authError gameObject may still be inactive (I assume).
The SetActive method works fine for me, so just make sure you're activating the right object and check if the rest of the code in that 'case' statement is getting called.
$$anonymous$$ust be this. Shall I add that you need to make sure that all the parent gameobjects are also active for the authError to be visible.
i only deactivate the main error panel. not the children. authError Text component is child of authErrorPanel. And why would the auhErrorPanel.SetActive(true);
stop the script? the code below never gets called. and text gets changed only in inspector but not in the scene.
is my switch statement ok?
public void DisplayError(string error)
{
Debug.LogWarning(error);
switch (error)
{
case "Firebase.FirebaseException: An email address must be provided.":
authError.text = "Enter Email Address";
auhErrorPanel.SetActive(true);
print("no email");
//loginPanel.ShowError("Enter Email Address");
//errorPanel.SetActive(true);
break;
case "Firebase.FirebaseException: A password must be provided.":
print("no password");
authError.text = "Enter Password";
auhErrorPanel.SetActive(true);
//loginPanel.ShowError("Enter Password");
//errorPanel.SetActive(true);
break;
case "Firebase.FirebaseException: The email address is badly formatted.":
//loginPanel.ShowError("Invalid Email");
//errorText.text = "Invalid Email";
//errorPanel.SetActive(true);
break;
case "Firebase.FirebaseException: There is no user record corresponding to this identifier. The user may have been deleted.":
//loginPanel.ShowError("Not Registered or Incorrect Email");
//errorText.text = "Not Registered or Incorrect Email";
//errorPanel.SetActive(true);
break;
case "Firebase.FirebaseException: The password is invalid or the user does not have a password.":
//loginPanel.ShowError("Incorrect Password");
//errorText.text = "Incorrect Password";
//errorPanel.SetActive(true);
break;
}
Your switch statement is fine, I just tried it out and it prints, enabled the GameObject and changes the text. I think they may be right in regards to something must not be hooked up correctly or perhaps something higher in your panels hierarchy needs to be enabled or something.
it is all hooked up correctly. here is how it all starts:
public void SignIn()
{
FirebaseAuth.DefaultInstance.SignInWithEmailAndPasswordAsync(loginPanel.email.text, loginPanel.password.text).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogWarning("SignInWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
FirebaseException error = task.Exception.Flatten().InnerExceptions[0] as FirebaseException;
string error$$anonymous$$sg = error.ToString();
DisplayError(error$$anonymous$$sg);
print("i never get printed too");
return;
}
});
}
Answer by zederis · Aug 08, 2019 at 06:46 PM
I got the correct game objects. there is something weird going on. I have noticed that the text is changed only in inspector, but not in the scene.. if i type in something manually, the text changes, but not through script.
yes. i get the print message in the console. i also noticed that if i put print message below the setActive it doesn't print anything.
There is definitely no error? Vague possibility that you clicked on the button to stop showing errors in the console.
also if i create a method just to activate the error panel and use that method on a button, the panel gets activated.
What types or classes are authError and auhErrorPanel?
public GameObject auhErrorPanel; public Text authError;
The authErrorPanel refers to a GameObject reference then correct?
Answer by cemcimrin · Aug 15, 2019 at 12:10 PM
https://stackoverflow.com/questions/53916533/setactive-can-only-be-called-from-the-main-thread
Here you can find why you can't use SetActive(), in task that is not mainthread task. Same happened to my project while switching from NET 3.5 equivalent to NET 4.0. in the link you have both 2 solutions. Hope it Helps.
Your answer
Follow this Question
Related Questions
game object set active on trigger enter? 3 Answers
activate GameObject dont work 1 Answer
Script is giving error that no MonoBehaviour scripts in file 0 Answers
show gameobject one time only 2 Answers
Gameobject flickering (Trigger issues?) 0 Answers