Unity Login & Authentication Minimal Example
Add VIVERSE login to a brand-new Unity project. You’ll import the VIVERSE package, build your own login UI, optionally enable the WebGL bridge, and test locally or on VIVERSE.
Overview
Add VIVERSE login to a brand-new Unity project: import the VIVERSE package, build a two-column login UI, optionally enable WebGL support, and test locally or on VIVERSE.
Prerequisites
Unity 2021 LTS or newer (install the WebGL module if you plan to target WebGL)
App ID from VIVERSE Studio (https://worlds.viverse.com/)
VIVERSE login/auth unitypackage (e.g., SDK_v0.96.unitypackage)
Quick Start: Download Pre-built Login Sample
If you prefer to use a pre-configured login sample instead of building it manually, you can download a ready-to-use Unity package that includes the complete login UI setup and scene.
Download the Login Sample Package: Login_Documentation_Sample.unitypackage
Important Import Order: You must import the packages in this specific order to avoid missing dependencies:
First: Import the VIVERSE SDK Unity package (SDK_v0.96.unitypackage)
Assets → Import Package → Custom Package… → Select your SDK package → Import
Second: Import TextMeshPro (if not already in your project)
Window → TextMeshPro → Import TMP Essential Resources
Third: Import the Login Sample package
Assets → Import Package → Custom Package… → Select
Login_Documentation_Sample.unitypackage→ Import
After importing all three packages, open the Login_Leaderboard_Documentation_Sample scene from Assets/Scenes/ to see the complete login example in action.
Note: If you prefer to build the login UI manually step-by-step, continue with the instructions below starting from Step 1.
Step 1. Import the VIVERSE package
Step 2. Build the two-column login UI
Setup Left Column (Buttons)
A. Right-click LoginPanel → Create Empty (rename to ButtonColumn).
B. Add a Vertical Layout Group to ButtonColumn:
Padding: all zero (leave the defaults)
Spacing: 20
Child Alignment: Upper Center
Disable Child Force Expand Width/Height.
C. With ButtonColumn selected, set the RectTransform anchor preset to "middle left" (Alt+Left in the anchor matrix).
D. Right-click ButtonColumn → UI → Button (TextMeshPro) (rename to LoginButton). In the RectTransform, set Width = 180, Height = 40; set the child text to "Login", font size ~24, color a dark gray (#333333).
E. Duplicate LoginButton, rename to ClearDataButton, change the label text to "Clear Data".
F. (Optional) Add a Content Size Fitter on ButtonColumn (Horizontal/Vertical Fit = Preferred Size) if you want the column to shrink-wrap the buttons.
Setup Right Column (Info Group)
A. Right-click LoginPanel → Create Empty (rename to InfoGroup).
B. Add a Vertical Layout Group to InfoGroup:
Padding: keep default zeros (0 on all sides)
Spacing: 18
Child Alignment: Upper Left
C. Set the RectTransform anchor preset to "middle right" (Alt+Right). In the RectTransform, set Width ≈ 500 and Height ≈ 103.
D. (Optional) Add a Content Size Fitter on InfoGroup.
Create Status Labels
A. Right-click InfoGroup → UI → Text - TextMeshPro (rename to StatusText):
Text: "Status: Ready", font size ~20, color #000000
On the TextMeshPro component, set Alignment to Upper Left.
In the RectTransform, set Width ≈ 500 and Height ≈ 30.
B. Duplicate StatusText twice:
First duplicate → rename the GameObject to AccountText and set its TextMeshPro text to "Account: ".
Second duplicate → rename the GameObject to TokenText and set its TextMeshPro text to "Token: ".
Keep the same RectTransform Width ≈ 500 and Height ≈ 30 on each duplicate.
This two-column layout provides a clean, organized interface for VIVERSE authentication. The left column contains action buttons (Login and Clear Data) that trigger the authentication flow and data management. The right column displays real-time feedback including login status, account information, and token details. This separation of controls and information makes it easy for users to understand the authentication state at a glance while providing clear actions to initiate or reset the login process. The UI will be wired to the LoginUIController script in the next step, which will update these labels dynamically as the authentication flow progresses.
Step 3. Add the controller script
Step 4. Attach HttpServer (Editor/Windows testing)
Add HttpServer Component
With LoginPanel selected, add the HttpServer component (included in the package). LoginManager references it automatically for local redirect flow.
Why HttpServer is needed:
The HttpServer component is essential for testing authentication in the Unity Editor and Windows standalone builds. Here's how the authentication flow works:
Browser Redirect Flow: When you click Login in Editor/Windows mode,
LoginManageropens your default browser and navigates to the VIVERSE login page.Callback Handling: After successful authentication, VIVERSE redirects the browser back to a localhost URL (
http://localhost:40078/) with the authentication tokens.Local Server: The
HttpServercomponent runs a local HTTP server on port 40078 that listens for this redirect. It receives the authentication callback data (access token and account ID) from the browser.Data Processing: The server processes the callback, extracts the authentication credentials, and saves them to
PlayerPrefsso your Unity application can access them.Unity Integration: The saved credentials are then used by
LoginManagerto complete the login process within Unity.
Note: This component is only needed for Editor and Windows builds. For WebGL builds, the authentication is handled directly by the JavaScript bridge (.jslib file), so HttpServer is not required.
Step 5. WebGL bridge (only for WebGL builds)
Step 6. Test the login flow
Step 7. Build & deploy to VIVERSE
Publishing to Viverse
Publishing to Viverse documentation can be found here.
Login service data contract
LoginManager deserializes login results into:
Tokens and account IDs are cached via PlayerPrefs. Clear them with LoginManager.ClearLoginData() when logging out or switching accounts.
Last updated
Was this helpful?



