Unity Leaderboard Minimal Example
Build a minimal Unity demo showcasing VIVERSE Leaderboard SDK features: query rankings, submit scores, and validate data types.
Overview
Build a minimal Unity demo showcasing VIVERSE Leaderboard SDK features: query rankings, submit scores, and validate data types.
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)
User must be logged in via LoginManager before using Leaderboard SDK features
Leaderboard Meta (API Name) created in VIVERSE Studio (https://studio.viverse.com/upload)
Quick Start: Download Pre-built Leaderboard Sample
If you prefer to use a pre-configured leaderboard sample instead of building it manually, you can download a ready-to-use Unity package that includes the complete leaderboard UI setup and scene.
Download the Leaderboard Sample Package: Leaderboard_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: Set up Login (Required)
The Leaderboard SDK requires authentication. You must have LoginManager set up in your project before using the leaderboard features. If you haven't set up login yet, follow the Login & Authentication Guide or import the Login Sample package first.
Fourth: Import the Leaderboard Sample package
Assets → Import Package → Custom Package… → Select
Leaderboard_Documentation_Sample.unitypackage→ Import
After importing all packages, open the Leaderboard_Documentation_Sample scene from Assets/Scenes/ to see the complete leaderboard example in action.
Note: If you prefer to build the leaderboard UI manually step-by-step, continue with the instructions below starting from Step 1.
Step 1. Import the VIVERSE package
Step 2. Setup Login (Required for Leaderboard SDK)
Setup Login First
The Leaderboard SDK requires authentication. Follow the Login & Authentication guide to set up:
LoginManager component
Login UI with Login button
App ID configuration
HttpServer component (for Editor/Windows testing)
Ensure you can successfully log in before proceeding to Leaderboard SDK setup. In the screenshot below, we've created a prefab from the LoginPanel that gets built in the Login & Authentication guide. We've exported the prefab along with LoginUIController.cs

Step 3. Build the Leaderboard SDK UI

Create Main Container
A. Right-click LeaderboardCanvas → Create Empty → rename to MainContainer
B. Add Component → Layout → Vertical Layout Group
C. Set Vertical Layout Group properties:
Child Alignment: Upper Left
Padding: Left = 20, Right = 20, Top = 20, Bottom = 60
Spacing: 30
Child Force Expand: Width = true, Height = false
D. In RectTransform, set Anchor Presets to stretch-stretch (hold Alt+Shift), then set all margins to 0
Create Status Bar Container
A. Right-click MainContainer → Create Empty → rename to StatusBar
Add Component → Layout → Horizontal Layout Group
Set Horizontal Layout Group properties:
Child Alignment: Middle Left
Padding: Left = 20, Right = 20, Top = 10, Bottom = 10
Spacing: 0
In RectTransform, set Height = 40
Add Component → Layout → Layout Element
Set Layout Element: Preferred Height = 40, Flexible Height = 0, Flexible Width = 1
B. Right-click StatusBar → UI → Text - TextMeshPro → rename to StatusText
Text: "Status: Ready - Please login first"
Font Size: 14
Alignment: Center
In RectTransform, set Width = 800, Height = 30
Add Component → Layout → Layout Element
Set Layout Element: Preferred Width = 800, Flexible Width = 1
Create Settings Panel
A. Right-click MainContainer → Create Empty → rename to SettingsPanel
Add Component → Layout → Vertical Layout Group
Set Vertical Layout Group properties:
Child Alignment: Upper Left
Padding: All = 15
Spacing: 10
Child Force Expand: Width = true, Height = false
In RectTransform, set Width = 450, Height = 300
Add Component → Layout → Layout Element
Set Layout Element: Preferred Width = 450, Preferred Height = 300
B. Create Section Header:
Right-click SettingsPanel → UI → Text - TextMeshPro → rename to SettingsHeader
Text: "Leaderboard Settings"
Font Size: 24, Font Style: Bold
Alignment: Left
In RectTransform, set Height = 35 and Width = 300
C. Create Input Fields Container:
Right-click SettingsPanel → Create Empty → rename to InputFieldsContainer
Add Component → Layout → Vertical Layout Group
Set Vertical Layout Group properties:
Spacing: 8
Padding: Top = 5, Bottom = 5
Child Force Expand: Width = true, Height = false
In RectTransform, set Height = 150
D. Create Input Field:
Right-click InputFieldsContainer → UI → Input Field - TextMeshPro → rename to ScoreInput
Placeholder text: "Score"
Font Size: 14
In the input field's RectTransform, set Height = 35
E. Create Data Type Dropdown:
Right-click InputFieldsContainer → UI → Dropdown - TextMeshPro → rename to DataTypeDropdown
In RectTransform, set Height = 35
Options: "Numeric (Points)", "Seconds (Time)", "Milliseconds (Time)"

Create Buttons Panel
A. Right-click MainContainer → Create Empty → rename to ButtonsPanel
Add Component → Layout → Vertical Layout Group
Set Vertical Layout Group properties:
Child Alignment: Upper Left
Padding: All = 15
Spacing: 10
Child Force Expand: Width = true, Height = false
In RectTransform, set Width = 450, Height = 200
Add Component → Layout → Layout Element
Set Layout Element: Preferred Width = 450, Preferred Height = 200
B. Create Section Header:
Right-click ButtonsPanel → UI → Text - TextMeshPro → rename to ButtonsHeader
Text: "Leaderboard Actions"
Font Size: 24, Font Style: Bold
Alignment: Left
In RectTransform, set Height = 35
C. Create Buttons:
Right-click ButtonsPanel → UI → Button (TextMeshPro) → rename to ValidateDataTypeButton
Change button text to "Validate Data Type"
Font Size: 16
In the button's RectTransform, set Height = 40
Right-click ButtonsPanel → UI → Button (TextMeshPro) → rename to UploadScoreButton
Change button text to "Upload Score"
Font Size: 16
In the button's RectTransform, set Height = 40
Right-click ButtonsPanel → UI → Button (TextMeshPro) → rename to GetLeaderboardButton
Change button text to "Get Leaderboard"
Font Size: 16
In the button's RectTransform, set Height = 40
Create Leaderboard Display Panel
A. Right-click MainContainer → Create Empty → rename to LeaderboardPanel
Add Component → Layout → Vertical Layout Group
Set Vertical Layout Group properties:
Child Alignment: Upper Left
Padding: All = 15
Spacing: 10
Child Force Expand: Width = true, Height = false
In RectTransform, set Width = 600, Height = 500
Add Component → Layout → Layout Element
Set Layout Element: Preferred Width = 600, Preferred Height = 500
B. Create Section Header:
Right-click LeaderboardPanel → UI → Text - TextMeshPro → rename to LeaderboardHeader
Text: "Leaderboard Rankings"
Font Size: 24, Font Style: Bold
Alignment: Left
In RectTransform, set Height = 35
C. Create Scroll View:
Right-click LeaderboardPanel → UI → Scroll View → rename to LeaderboardScrollView
In RectTransform, set Width = 570, Height = 450
Remove the default Horizontal Scrollbar (delete it from Hierarchy)
Select the ScrollRect component and uncheck "Horizontal"
D. Setup Scroll View Content:
Select LeaderboardScrollView → Viewport → Content (child object)
Add Component → Layout → Vertical Layout Group
Set Vertical Layout Group properties:
Child Alignment: Upper Left
Padding: All = 10
Spacing: 20
Child Force Expand: Width = true, Height = false
Add Component → Layout → Content Size Fitter
Set Content Size Fitter: Vertical Fit = Preferred Size
In RectTransform, set anchor preset to top left (hold Shift and Alt to set pivot and position)
E. Create Horizontal Container for Settings and Buttons:
Right-click MainContainer → Create Empty → rename to TopRow
Add Component → Layout → Horizontal Layout Group
Set Horizontal Layout Group properties:
Child Alignment: Upper Left
Padding: All = 0
Spacing: 30
Child Force Expand: Width = false, Height = false
Move SettingsPanel and ButtonsPanel to be children of TopRow (drag in Hierarchy)
In RectTransform, set Height = 200.
Verify UI Setup
A. Check Hierarchy Structure: Your Hierarchy should look like:
B. Test Layout:
Press Play to see your UI in the Game view
Verify all elements are visible and properly organized
Check that panels are properly arranged with spacing
Verify status bar is at the top
Test scroll view functionality
C. Fine-tune if needed:
Adjust spacing in Layout Groups if elements are too close/far
Modify panel widths if content doesn't fit
Adjust font sizes for better readability
Use RectTransform anchors for responsive positioning
D. Stop Play mode before continuing to next step.
Step 4. Add the Leaderboard SDK controller script
Wire Serialized Fields
Select LeaderboardController in Hierarchy.
In Inspector, you'll see LeaderboardUIController component with many empty fields.
Set App Id field → enter your VIVERSE App ID (same one used for LoginManager).
Set Api Name field → enter your Leaderboard Meta Name (API Name) from VIVERSE Studio.
Drag UI elements from Hierarchy into the corresponding fields:
Score Input → drag ScoreInput from Hierarchy
Data Type Dropdown → drag DataTypeDropdown from Hierarchy
Validate Data Type Button → drag ValidateDataTypeButton from Hierarchy
Upload Score Button → drag UploadScoreButton from Hierarchy
Get Leaderboard Button → drag GetLeaderboardButton from Hierarchy
Leaderboard Container → drag Content (from LeaderboardScrollView) from Hierarchy
Status Text → drag StatusText from Hierarchy
Tip: You can also use the circle target picker next to each field to select objects from a popup window.
Step 5. Test all Leaderboard SDK features
Test Data Type Validation
Press Play in Unity Editor.
Click Login (from your LoginManager setup) and complete authentication in the browser.
Wait for login to complete—StatusText should show "Logged in - Ready to use Leaderboard SDK".
Test Data Type Validation:
Ensure API Name is set in the LeaderboardUIController Inspector (set in Step 4)
Select the appropriate Data Type from dropdown (Numeric, Seconds, or Milliseconds)
Click Validate Data Type button
StatusText should show "Data type validation passed" or an error message if there's a mismatch
What to verify:
✅ Validation works when logged in
✅ Error message appears if data type doesn't match server configuration
✅ Success message appears when data type matches
✅ StatusText shows validation results
Note: The data type must match the configuration in VIVERSE Studio. If you get a mismatch error, check your leaderboard settings in VIVERSE Studio and update the dropdown selection accordingly.
Test Score Submission
With user logged in, test Score Submission:
Ensure API Name is set in the LeaderboardUIController Inspector (set in Step 4)
Select the correct Data Type from dropdown
Enter a Score value in ScoreInput field
For Numeric: Enter a number (e.g., "1000")
For Seconds: Enter time in seconds (e.g., "65.5" for 1 minute 5.5 seconds)
For Milliseconds: Enter time in milliseconds (e.g., "65500" for 65.5 seconds)
Click Upload Score button
StatusText should show "Score uploaded successfully!"
What to verify:
✅ Score submission works when logged in
✅ Success message appears on successful upload
✅ Error message appears if data type validation fails
✅ StatusText shows operation results
✅ Score is properly formatted based on data type
Note: Score submission uses secure encryption (Ironhide). Each submission creates or updates your ranking on the leaderboard.
Test Leaderboard Query
With user logged in, test Leaderboard Query:
Ensure API Name is set in the LeaderboardUIController Inspector (set in Step 4)
Click Get Leaderboard button
StatusText should show "Leaderboard loaded - X players"
Leaderboard entries should appear in the scroll view
What to verify:
✅ Leaderboard query works when logged in
✅ Top 10 records are displayed
✅ Rankings are sorted correctly (rank 0 = #1, rank 1 = #2, etc.)
✅ Scores are formatted correctly based on data type
✅ Player names and scores are displayed
✅ Scroll view works for multiple entries
Leaderboard Display Format:
Each entry shows: Rank, Player Name, and Formatted Score
Numeric scores: "1000 pts"
Seconds: "01:05.50" (mm:ss.ff)
Milliseconds: "01:05.500" (mm:ss.fff)
Verify Feature Coverage
Ensure all Leaderboard SDK features are tested:
✅ Data Type Validation (ValidateDataTypeAsync)
✅ Score Submission with Data Type (SubmitScoreWithDataTypeAsync)
✅ Leaderboard Query (GetLeaderboardRecordsAsync)
✅ Secure score encryption (Ironhide)
✅ Multiple data types (Numeric, Seconds, Milliseconds)
✅ Error handling (no login, invalid API name, data type mismatch)
✅ UI feedback (status messages, button states)
✅ Score formatting based on data type
Step 6. Build & deploy to VIVERSE
Leaderboard SDK data contracts
LeaderboardRecord structure
LeaderboardRecord:
LeaderboardMeta structure
LeaderboardMeta:
LeaderboardRankingResponse structure
LeaderboardRankingResponse:
Data Types
LeaderboardDataType enum:
Important: The data type must match the server configuration in VIVERSE Studio. Use ValidateDataTypeAsync to check compatibility before submitting scores.
Score Submission
ScoreEntry structure:
Note: Score submission uses secure encryption (Ironhide) with RSA key exchange and AES encryption. The process involves:
Generating RSA key pair
Requesting session token from Ironhide API
Decrypting symmetric key with RSA private key
Encrypting score data with AES
Submitting encrypted data to Leaderboard API
API Methods
LeaderboardService provides these methods:
ValidateDataTypeAsync(appId, userAuthKey, apiName, clientDataType)- Validate data type matches serverGetLeaderboardRecordsAsync(appId, userAuthKey, apiName, rangeStart, rangeEnd)- Get leaderboard rankingsSubmitScoreWithDataTypeAsync(appId, userAuthKey, apiName, scoreValue, dataType)- Submit score with validationSubmitScoreSecureAsync(appId, userAuthKey, scores)- Secure score submission (internal)
Authentication Requirements
All Leaderboard SDK operations require:
Valid LoginManager instance in the scene
User must be logged in (access token available)
App ID must be configured in LeaderboardUIController
API Name (Meta Name) must exist in VIVERSE Studio
Leaderboard SDK automatically validates authentication before each operation and will show appropriate error messages if login is required.
Score Formatting
Scores are automatically formatted based on data type:
Numeric: "1000 pts" (whole numbers)
Seconds: "01:05.50" (mm:ss.ff format)
Milliseconds: "01:05.500" (mm:ss.fff format)
The formatting is handled automatically by FormatScoreDisplay() method in the UI controller.
Troubleshooting
Buttons don't work:
Make sure you're logged in (StatusText should say "Logged in")
Check that all UI references are wired in LeaderboardUIController Inspector
Verify EventSystem exists in the scene (auto-created with Canvas)
"Please login first" error:
Ensure LoginManager is in the scene and initialized
Complete the login flow in browser (for Editor) or via WebGL
Check that access token is saved (LoginManager.IsLoggedIn should be true)
"Data Type Error" message:
Check your leaderboard configuration in VIVERSE Studio
Verify the data type setting matches between Unity Inspector and VIVERSE Studio
Use the "Validate Data Type" button to check compatibility
Update the Data Type dropdown to match server configuration
"No leaderboard data found":
Verify API Name is correct (case-sensitive)
Check that the leaderboard exists in VIVERSE Studio
Ensure at least one score has been submitted to the leaderboard
Check Unity Console for detailed error messages
Score submission fails:
Verify API Name is correct
Check data type matches server configuration
Ensure network connection is available
Check Unity Console for encryption or network errors
Verify LoginManager has valid access token
UI elements not visible:
Check Canvas Render Mode is "Screen Space - Overlay"
Verify UI elements are children of the Canvas
Try adjusting RectTransform positions in Inspector
Check Game view resolution matches your screen
Leaderboard entries not displaying:
Verify leaderboardContainer is assigned (should be Content from ScrollView)
Check that GetLeaderboard was successful (check StatusText)
Ensure leaderboard has data (submit a score first)
Check Unity Console for parsing errors
Score formatting incorrect:
Verify Data Type dropdown matches the leaderboard's data type
Check that score values are in the correct format:
Numeric: whole numbers (e.g., 1000)
Seconds: decimal seconds (e.g., 65.5)
Milliseconds: whole milliseconds (e.g., 65500)
API Name not found:
Verify the API Name (Meta Name) exists in VIVERSE Studio
Check for typos or case sensitivity issues
Ensure the leaderboard is created and published in VIVERSE Studio
Visit https://studio.viverse.com/upload to create or verify leaderboard metas
Last updated
Was this helpful?