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.
Unity Login & Authentication Minimal Example (New Project)
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.92 1.unitypackage)
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.
Step 3. Add the controller script
Step 4. Attach HttpServer (Editor/Windows testing)
Step 5. WebGL bridge (only for WebGL builds)
Step 6. Test the login flow
Step 7. Build & deploy to VIVERSE
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?



