- Home /
Question by
hexols · Apr 29 at 07:18 AM ·
c#gameobjectunityeditorgame development#pragma
Cannot Send Class Object From One Scene to Another
I’m developing a Unity game. I have a login scene in the game that fetches user information from the database. After fetching the user information, a model class which is named as RegisteredUser is used to hold the user credentials. I need to send the created RegisteredUser class object to the next scene. But I cannot send it directly. When I try it, I get NullExceptionError and the object is lost. How can I fix it? This is the callback function that user credentials are returned:
public void userInfo (RegisteredUser newUser)
{
loggedinUser.FirstName = newUser.FirstName;
loggedinUser.LastName = newUser.LastName;
loggedinUser.Email = newUser.Email;
loggedinUser.Gender = newUser.Gender;
}
And this is the part where I want to fetch the name and surname of the user to print on the text field:
void Start()
{
// string userName = currentUser.FirstName + currentUser.LastName;
welcomeText = GameObject.Find("Canvas/SidebarPanel/WelcomeText").GetComponent<Text>();
}
Comment
Best Answer
Answer by KloverGames · Apr 29 at 02:02 PM
The object that's storing the class and you want to move to the next scene has to be marked as DontDestroyOnLoad();