Login + Authentication

The Asset Layer Unity SDK comes with a scene called LoginScene which is used to handle player authentication. The scene is designed to work regardless of platform (browser, mobile, or desktop). However, the way in which authentication occurs varies based on platform. Please see the sections below for details.

To find the LoginScene, first make sure you have imported the essentials package Unity App Setup. Then, you'll see the LoginScene in Assets/AssetLayerUnitySDK/Scenes. You can customize the LoginScene per your requirements.

WebGL Login

In a browser based context, authentication should happen through the website into which the WebGL build is integrated. The Login Scene remains inactive until the SetDidToken method of the LoginReceiver GameObject is called. This method is designed to be triggered from the web environment, allowing messages to be sent to specific GameObjects within the Unity WebGL build. To ensure smooth operation, it is crucial to verify that Unity has fully loaded the Login Scene before sending any messages. You can facilitate this by setting the Login Scene as the initial scene in your Unity application and confirming that the Unity startup process has completed prior to message transmission.

You can view more details on sending messages between your web app and WebGL Unity environments in the following sections:

Deploying Your Unity WebGL Game Through Sample App

Desktop Login

For desktop builds, the login scene will provide a button that when clicked will open a webpage where the user can login.

This webpage can be set in the Asset Layer section of the project settings under "Login URL". That page will then return the DID token to the Unity app. Upon clicking the login button, the Login Scene initiates a local HttpServer. For web login, a Get Request containing the Did Token should be sent to http://localhost:8080/loginUnity/, appending a token parameter. Following the reception of this request, the token undergoes a validity check. If valid, the scene specified in the LoginReceiver GameObject will be loaded.

Mobile Login

For mobile login, users are able to generate their DID token within the app. The LoginScene prompts users for their email address and then the user is sent a one-time passcode. Once the passcode is entered correctly, the DID token is generated and the scene specified in the LoginScene is loaded.

Last updated