Login Implementation

Added Login Screen


  • Login Scene Addition: Added a new LoginScene with a UI composed of TMP_InputFields for username/password, a Toggle for “Remember Me,” a Button for login, a Button for signup and a Button for sign-out (ImageAbove). 
  • Cloud Save Integration: Imported the Unity Cloud Save package and initialized Unity Services in LoginManager.cs to support user authentication and persistent data storage.
  • Authentication Flow: In LoginManager.cs, implemented SignupButtonPressed(), LoginButtonPressed() and SignOut() methods using Unity.Services.Authentication for sign-up/sign-in and Unity.Services.CloudSave to store the player’s username on first login.
  • Session Persistence: Used PlayerPrefs to store credentials when “Remember Me” is toggled, and reload them on startup in LoadSavedCredentials().
  • Scene Transition: After successful login, deferred by 2 s, the script calls PhotonNetwork.LoadLevel(2) to move into the Main Menu (Game scene index 2)

// Key portions of LoginManager.cs
public async void Start()
{
    await InitializeUnityServices();
    LoadSavedCredentials();
    loginButton.interactable = true;
    signOutButton.onClick.AddListener(SignOut);
    signOutButton.gameObject.SetActive(false);
}
...
public async void SignupButtonPressed() { /* SignUpWithUsernamePasswordAsync */ }
public void LoginButtonPressed() { /* SignInWithUsernamePasswordAsync */ }
public void SignOut() { AuthenticationService.Instance.SignOut(); SceneManager.LoadScene("LoginScene"); }

Related games implementation features and practices

  • Many online titles (e.g., Fortnite, Minecraft) employ dedicated login scenes with cloud-backed save systems to sync player profiles across devices.
  • “Remember Me” toggles paired with secure storage of tokens (rather than raw passwords) are standard to streamline return visits.
  • Separating authentication into its own scene improves code modularity and UX flow—matching industry best practices for account management.

Analysis of implementation

  • Metrics to Track:
  • - Sign-up success percentage vs. validation errors.
  • - Login failure modes (invalid creds, network timeouts).
  • - Cloud Save latency and failure counts.
Results and Feedback

  • Auto-Fill Issue: “Remember Me” credentials are stored but not repopulated correctly LoadSavedCredentials() needs debugging.
  • Workflow Friction: After sign-up, users must restart the app to log in consider automatically invoking the login flow post-signup.
  • Sign-Out Flow: Currently requires re-entering credentials to sign out; needs refinement to clear inputs and toggle UI state immediately.
  • Next Steps: Fix the LoadSavedCredentials() call order, implement in-scene login after sign-up, and ensure SignOut() resets all UI fields without manual input.

References

  • Unity Services Authentication: https://docs.unity.com/ugs/manual/authentication/manual/overview
  • Unity Cloud Save Documentation: https://docs.unity.com/ugs/manual/cloud-save/manual



Comments

Popular posts from this blog

Basic Implementation