Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by Victor Nedelea · May 03, 2021 at 02:23 AM · Player Dataunity3d

How to register player at startup in Unity?

So, I simply want to create a registration menu and I've already done that. What I need help with is this:

1)If a player enters for the first time in the application, it means that it has no DeviceID and thus it needs to be created and only for this time, the player will have to insert the Username, Email and Password and after clicking the Submit button the app should continue.

2)If the player enters the app from the same device, it will automatically Log In without asking for any details since the Device ID exists in the database.

Thanks.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Sarah Zhang · May 03, 2021 at 09:54 AM

To implement your requirements, you need to keep the field “CreateAccount” of login API such as LoginWithAndroidDeviceID as “true” and do the API call in the Unity Start() function. Besides, you should add the judgment for the response of login API, if the value of “NewlyCreated” is true, it means it’s the first time for the player to enter the game, the player needs to provide the username, email, and password, and you should call the API AddUsernamePassword to submit the information. If the value of “NewlyCreated” false, it means it’s not the player’s first login, the player can enter the game directly. You can refer to the document -- Login basics and best Practices - PlayFab | Microsoft Docs for more information about best practice of integrating anonymous login and recoverable login.

The possible code sample could be something like this.

using PlayFab;
using PlayFab.ClientModels;
using System;
using UnityEngine;
using UnityEngine.UI;


public class LoginSample : MonoBehaviour
{
    public InputField UsernameInputField;
    public InputField EmailInputField;
    public InputField PasswordInputField;


    void Start()
    {
        var request = new LoginWithAndroidDeviceIDRequest { AndroidDeviceId = "GettingStartedGuide", CreateAccount = true };
        PlayFabClientAPI.LoginWithAndroidDeviceID(request, OnLoginSuccess, OnFailure);
    }


    private void OnLoginSuccess(LoginResult result)
    {
        if (result.NewlyCreated)
        {
            //Display InputField UI
            var addUsernamePasswordRequest = new AddUsernamePasswordRequest { Username = UsernameInputField.text, Email = EmailInputField.text, Password = PasswordInputField.text };
            PlayFabClientAPI.AddUsernamePassword(addUsernamePasswordRequest, OnAddSuccess, OnFailure);
        }
        else
        {
            //Enter the game logic
        }
    }


    private void OnAddSuccess(AddUsernamePasswordResult result)
    {
        //Enter the game logic 
    }


    private void OnFailure(PlayFabError error)
    {
        Debug.LogError(error.GenerateErrorReport());
    }
}
Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    ,How to post user points to a certain leaderboard and get the leaderboard back in Unity? 1 Answer

    Upload a file to player account From UNITY 3 Answers

    Saving a custom character as a JSON 1 Answer

    Stay logged in when the scene changes 1 Answer

    How can I Store a list of strings or integers in Playfab 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges