Skip to content

Configuration

Daisuke Tsukada edited this page Aug 26, 2025 · 1 revision

Configuration Guide

This guide covers all configuration options for Unity Remote Server.

Server Configuration

Port Configuration

By default, the server listens on port 8787. You can change this in your Unity Editor script:

using DSGarage.UnityRemoteServer;
using UnityEditor;

[InitializeOnLoad]
public static class CustomServerConfig
{
    static CustomServerConfig()
    {
        RemoteServer.Port = 8080; // Custom port
        RemoteServer.EnableDebugLogging = true; // Enable debug logs
    }
}

Binding Address

For security, the server only binds to localhost (127.0.0.1) by default. This prevents external access.

WARNING: Changing the binding address can expose your Unity Editor to network attacks. Only change this if you understand the security implications.

Custom Endpoints

You can add custom API endpoints to extend functionality:

using DSGarage.UnityRemoteServer;
using UnityEditor;
using System.Net;

[InitializeOnLoad]
public static class CustomEndpoints
{
    static CustomEndpoints()
    {
        // Register custom endpoint
        RemoteServer.RegisterCustomEndpoint("/custom/test", HandleCustomTest);
    }
    
    static void HandleCustomTest(HttpListenerContext context)
    {
        // Your custom logic here
        var response = new
        {
            ok = true,
            message = "Custom endpoint response",
            timestamp = System.DateTime.Now
        };
        
        RemoteServer.SendJsonResponse(context, response);
    }
}

Environment Variables

Configure behavior using environment variables:

Variable Description Default
UNITY_REMOTE_PORT Server port 8787
UNITY_REMOTE_DEBUG Enable debug logging false
UNITY_REMOTE_TIMEOUT Default timeout (seconds) 120

Example:

export UNITY_REMOTE_PORT=8080
export UNITY_REMOTE_DEBUG=true

Build Configuration

Configure build settings via the API:

{
  "platform": "android",
  "outputPath": "Builds/game.apk",
  "scenes": ["Assets/Scenes/Main.unity"],
  "development": false,
  "compress": true,
  "scriptingBackend": "IL2CPP",
  "targetArchitecture": "ARM64"
}

Platform-Specific Options

Android

  • keystorePath: Path to keystore file
  • keystorePassword: Keystore password
  • packageName: Application ID
  • versionCode: Version code
  • splitAPKs: Enable App Bundle

iOS

  • teamId: Apple Developer Team ID
  • bundleIdentifier: Bundle ID
  • provisioningProfile: Profile name
  • targetSDK: iOS SDK version

Windows

  • architecture: x86 or x64
  • copyPDBFiles: Include debug symbols

Logging Configuration

Log Levels

Control which logs are captured:

LogStore.MaxEntries = 1000; // Maximum log entries
LogStore.CaptureStackTraces = true; // Include stack traces
LogStore.LogLevels = LogType.Error | LogType.Warning; // Log levels to capture

Log Filtering

Filter logs by pattern:

LogStore.AddFilter("UnityEngine.*"); // Ignore Unity internal logs
LogStore.AddFilter("System.Reflection.*"); // Ignore reflection logs

Performance Tuning

Compilation Settings

// Adjust compilation wait behavior
RemoteOps.CompilationCheckInterval = 0.5f; // Check every 500ms
RemoteOps.MaxCompilationWait = 300f; // Maximum 5 minutes

Memory Management

// Limit memory usage
LogStore.MaxEntries = 500; // Reduce log buffer
RemoteServer.MaxRequestSize = 10 * 1024 * 1024; // 10MB max request

Security Configuration

Access Control

Implement basic access control:

public class SecurityConfig
{
    static HashSet<string> allowedHosts = new HashSet<string>
    {
        "127.0.0.1",
        "localhost"
    };
    
    public static bool IsAllowed(HttpListenerContext context)
    {
        var host = context.Request.RemoteEndPoint.Address.ToString();
        return allowedHosts.Contains(host);
    }
}

Request Validation

Validate incoming requests:

RemoteServer.RegisterRequestValidator((context) =>
{
    // Check custom headers
    var apiKey = context.Request.Headers["X-API-Key"];
    return apiKey == "your-secret-key";
});

Troubleshooting Configuration Issues

Port Already in Use

If port 8787 is already in use:

  1. Change the port in configuration
  2. Or find and stop the conflicting process:
# Find process using port 8787
lsof -i :8787  # macOS/Linux
netstat -ano | findstr :8787  # Windows

# Kill the process
kill -9 <PID>  # macOS/Linux
taskkill /PID <PID> /F  # Windows

Configuration Not Loading

Ensure your configuration script:

  1. Is in an Editor folder
  2. Has [InitializeOnLoad] attribute
  3. Has a static constructor

Debug Configuration

Enable verbose logging:

RemoteServer.EnableDebugLogging = true;
Debug.Log($"Server running on port: {RemoteServer.Port}");
Debug.Log($"Custom endpoints: {RemoteServer.GetCustomEndpoints().Count}");

Configuration File Example

Create remote-server.json in your project root:

{
  "server": {
    "port": 8787,
    "debugLogging": false,
    "timeout": 120
  },
  "build": {
    "defaultPlatform": "android",
    "outputDirectory": "Builds",
    "development": false
  },
  "logging": {
    "maxEntries": 1000,
    "captureStackTraces": true,
    "levels": ["error", "warning"]
  }
}

Load configuration:

[InitializeOnLoad]
public static class ConfigLoader
{
    static ConfigLoader()
    {
        var configPath = "remote-server.json";
        if (File.Exists(configPath))
        {
            var json = File.ReadAllText(configPath);
            var config = JsonUtility.FromJson<ServerConfig>(json);
            ApplyConfiguration(config);
        }
    }
}