Skip to content

Secrets Quick Start

This guide walks you through setting up and using Secrets to protect your sensitive data.

Opening the Secrets Editor

Access the Secrets Editor from Unity’s menu bar:

  1. Navigate to RetroDev > Secrets Editor
  2. The Secrets Editor window will open

The editor provides a simple interface to manage all your secret key-value pairs.

Adding Secrets

To add a new secret:

  1. Scroll to the bottom of the Secrets Editor
  2. Enter your key in the Secret Key field (e.g., API_KEY)
  3. Enter your value in the Secret Value field (e.g., sk_live_abc123xyz)
  4. Click Add Secret

Your secret is now stored securely and ready to use at runtime.

Managing Existing Secrets

The Secrets Editor displays all active secrets with inline editing:

  • Edit values: Click any value field and type to update it
  • Delete secrets: Click the Delete button next to any secret
  • View all secrets: Scroll through the list to see everything stored

Changes are saved automatically when you modify values.

Accessing Secrets at Runtime

Retrieve your secrets in code using the Secrets class:

using RetroDev.Secrets;
using UnityEngine;
public class APIManager : MonoBehaviour
{
private Secrets secrets;
private void Awake()
{
// Initialize the Secrets object
secrets = new Secrets();
}
private void Start()
{
// Retrieve a secret by its key
string apiKey = secrets.GetSecret("API_KEY");
// Use the secret to initialize your service
InitializeAPI(apiKey);
Debug.Log("API initialized with secure key");
}
private void InitializeAPI(string key)
{
// Your API initialization code here
}
}

Complete Example

Here’s a practical example using multiple secrets:

using RetroDev.Secrets;
using UnityEngine;
public class BackendService : MonoBehaviour
{
private Secrets secrets;
private string serverURL;
private string authToken;
private string apiKey;
private void Awake()
{
secrets = new Secrets();
}
private void Start()
{
// Load all your secrets at startup
serverURL = secrets.GetSecret("SERVER_URL");
authToken = secrets.GetSecret("AUTH_TOKEN");
apiKey = secrets.GetSecret("API_KEY");
// Initialize your backend connection
ConnectToBackend();
}
private void ConnectToBackend()
{
// Use your secrets to establish secure connections
Debug.Log($"Connecting to {serverURL}");
// Your connection logic here
}
}

Best Practices

Organize Your Keys

Use clear, descriptive key names with consistent naming conventions:

API_KEY
SERVER_URL
AUTH_TOKEN
PAYMENT_GATEWAY_KEY
ANALYTICS_ID

Validate Before Use

Always check that your secrets exist before using them:

private void InitializeServices()
{
string apiKey = secrets.GetSecret("API_KEY");
if (string.IsNullOrEmpty(apiKey))
{
Debug.LogError("Missing API_KEY - check Secrets Editor");
return;
}
// Safe to use the key now
StartService(apiKey);
}

Use Different Keys for Different Builds

Maintain separate secrets for development, staging, and production environments. Update them through the Secrets Editor before building for each environment.

Security Reminder

While Secrets protects against datamining and decompilation, remember:

  • This is for client-side secrets only
  • Critical operations should always happen server-side
  • Never store highly sensitive data (passwords, payment info) client-side
  • Use proper server authentication for any sensitive operations

For maximum security, your game should authenticate with your server, and the server should handle all sensitive operations using server-stored credentials.