Unity
Authentication

Authentication

Using our FractalLoginButton prefab is recommended to handle the authentication process across all platforms. This includes displaying the login prompt in the browser and subsequently verifying the authentication when the user returns into the game.

  • On desktop & mobile builds the default browser displays the authentication prompt. The player session is verified when returned to the game instance.
  • On WebGL builds the authentication prompt is displayed in a popup without exiting the game session.

Integrating the prefab in your game will help you set up the Fractal Account login in under a minute.

Authentication Prefab

Add Prefab to the Scene

Add the FractalLoginButton prefab to your game scene from the Prefabs/FractalSDK folder. Fractal Account prefab

The FractalLoginButton prefab should be nested inside UI > Canvas object. This will automatically create Fractal sign in button on your scene's UI layer. You can customize the button as needed. Prefab in scene

Configure the Authentication

When selecting the prefab from the scene hierarchy, notice that the object contains the Fractal Login Handler script inside the object Inspector.

Here you can configure the login process as needed:

  • Enter your project's API key (client id), obtained from Fstudio.
  • Select the required API scopes.
  • Attach to 3 available events, OnStarted, OnLogin, OnError, to customize the authentication behavior.
💡
You can use "dfrvfXn5agKbR6IP6GWXAom_MFIFd4MY" as Client Id for quick testing using our sample game project.

Fractal prefab configuration

Verify the Setup

You are all set up with the Fractal login. Verify by playing your scene in the Unity editor. SDK will log all of the outputs into the console, conveniently tagged with a [FRACTAL].

Fractal debug log

If everything works and you can see authenticated user's id, you can now call FractalClient to access user wallet across all scenes and objects. If you have issues specific to WebGL build, follow the additional project set up in the previous page.

Custom Authentication

If you plan to structure your scene differently or want to use a completely custom login button, you can use /FractalSDK/Scripts/FractalLoginHandler script and add it as a component to any object in your scene. You can set a target button in the Inspector to execute the authentication process.