Custom Interfaces
This guide shows you how to build your own industrial communication interfaces in realvirtual using the FastInterface framework. FastInterface provides thread-safe, high-performance communication with automatic signal management and connection handling.
Overview
realvirtual's FastInterface framework makes it easy to connect your simulation to external systems like PLCs, robots, IoT devices, or any system with a network API. You implement just three core methods, and FastInterface handles threading, reconnection, signal management, and UI integration automatically.
What you'll learn:
Setting up the FastInterface class structure
Implementing connection and communication logic
Handling signal exchange with thread safety
Using metadata for protocol mapping
Debugging and troubleshooting your interface
FastInterface Architecture

This diagram illustrates the streamlined FastInterface development approach:
FastInterface Foundation
The FastInterfaceBase class provides six core services automatically:
Thread Management: Handles background thread lifecycle
Auto Reconnection: Automatic connection recovery on failure
Signal Discovery: Finds and manages all child signal components
Error Handling: Comprehensive error recovery and logging
State Management: Connection status tracking and monitoring
Unity Integration: Seamless Inspector UI and Unity compatibility
Simple 3-Method Implementation
You only need to implement 3 methods to create a complete interface:
EstablishConnection() - Set up your protocol connection (TCP, serial, etc.)
CommunicationLoop() - Exchange data continuously with external system
CloseConnection() - Clean up resources and close connections
Data Flow Architecture
The bottom section shows the thread-safe data flow:
Unity Thread: Manages GameObjects and signal components
Background Thread: Runs your protocol implementation safely
External System: Your target device (PLC, Robot, IoT, Server)
Signal exchange uses built-in methods:
Reading Signals:
GetInputsForPLC()- Unity → External SystemWriting Signals:
SetOutputsFromPLC(data)- External System → Unity
Core Components:
FastInterfaceBase Class - The foundation that provides thread management, reconnection logic, and signal management infrastructure
Background Thread - All protocol communication runs on a dedicated background thread, keeping Unity's main thread responsive
Connection State Management - Automatic connection monitoring with visual status indicators and error reporting
Signal Manager - Handles automatic discovery of child signal objects and manages thread-safe signal data exchange
Thread-Safe Communication - Built-in mechanisms for safely passing data between Unity's main thread and the background communication thread
Precise Timing Control - Automatic integration with realvirtual's PrePost FixedUpdate system for deterministic signal processing (Available in realvirtual 6.0.5+)
Standard Workflow:
The architecture ensures a consistent pattern across all FastInterface implementations:
Initialize → Copy Inspector properties to thread-safe variables
Connect → Establish connection on background thread with automatic retry logic
Communicate → Continuous loop reading Unity signals, sending to external system, receiving responses, and updating Unity signals
Monitor → Real-time connection state tracking with performance metrics
Cleanup → Proper resource cleanup with graceful shutdown
Key Benefits:
Consistency - All custom interfaces follow the same proven architecture pattern
Reliability - Built-in connection recovery and error handling
Performance - Non-blocking communication with optimized signal change detection
Visibility - Inspector integration shows connection status, cycle counts, and timing metrics
Safety - Thread-safe design prevents Unity threading issues
This standardized approach means you can focus on implementing your specific protocol logic while FastInterface handles all the complex threading, connection management, and Unity integration automatically.
Precise Timing Control (realvirtual 6.0.5+)
FastInterface automatically integrates with realvirtual's PrePost FixedUpdate system to provide deterministic timing for industrial automation applications. This system ensures that all FastInterface components process signals at precisely the same moments relative to Unity's physics calculations.
Timing Architecture
Signal Processing Flow:
PreFixedUpdate Phase: All FastInterface instances synchronously process PLC outputs (data FROM PLC TO Unity objects)
FixedUpdate Phase: Unity runs physics calculations, component logic, and movement updates
PostFixedUpdate Phase: All FastInterface instances synchronously process PLC inputs (data FROM Unity objects TO PLC)
No Configuration Required: FastInterface automatically participates in the timing system - no additional setup or configuration needed.
FastInterface Inspector

The FastInterface Inspector provides comprehensive monitoring and configuration for your custom interfaces. Understanding these fields is essential for effective interface development and troubleshooting:
State Section
State: Shows the current connection status with visual indicators:
🟢 Connected (green) - Interface is connected and communicating successfully
🔴 Disconnected (red) - Interface is not connected
🟡 Connecting (yellow) - Interface is attempting to establish connection
🟠Error (orange) - Interface encountered an error and will attempt reconnection
Input Signals: Number of input signals (Unity → External System) discovered automatically
Output Signals: Number of output signals (External System → Unity) discovered automatically
Comm Cycle Ms: Actual communication cycle time in milliseconds (performance indicator)
Cycle Count: Total number of communication cycles completed since connection
Configuration Section
Update Cycle Ms: Target cycle time in milliseconds for communication loop
Only Transmit Changed Inputs: ✅ Performance optimization - only sends changed input values
Auto Reconnect: ✅ Automatically attempts reconnection on connection loss
Reconnect Interval Seconds: Wait time between reconnection attempts
Max Reconnect Attempts: Maximum number of consecutive reconnection attempts (-1 = infinite)
Debug Mode: ✅ Enables detailed logging for troubleshooting
Key Benefits of the Inspector:
Real-time Monitoring - Watch connection state and performance metrics live during runtime
Performance Optimization - "Only Transmit Changed Inputs" reduces network traffic significantly
Automatic Recovery - Built-in reconnection logic handles temporary connection losses
Development Support - Debug mode provides detailed logging for troubleshooting
Signal Discovery - Automatically counts and manages all child signal objects
Why use FastInterface:
Thread-safe background communication without blocking Unity
Automatic reconnection with customizable retry logic
Zero-configuration signal discovery - automatically finds all child signals
High performance with optimized signal exchange and change detection
Built-in debugging with comprehensive logging and state visualization
Quick Start with Template
The fastest way to create a custom interface is using the blueprint template. Copy one of these working templates from the realvirtual codebase:
BlueprintFastInterfaceSimple.cs- Minimal template for basic protocolsBlueprintFastInterface.cs- Full template with advanced features
Copy /Assets/realvirtual/Interfaces/Common/Fast/BlueprintFastInterfaceSimple.cs and replace the TODO sections with your protocol logic:
Step-by-Step Implementation
Step 1: Create Your Interface Class
Start by creating a new C# script that inherits from FastInterfaceBase:
Key points:
Always inherit from
FastInterfaceBaseAdd Inspector properties for connection settings
Declare connection objects as private fields
Use
[Header]attributes to organize Inspector settings
Step 2: Implement Connection Logic
The EstablishConnection method runs once on the background thread when starting communication:
Important:
Use
ThreadSafeLoggerinstead ofDebug.Login background threadsThrow exceptions on connection failure - FastInterface handles reconnection automatically
Copy Inspector properties to thread-safe fields using
CopyPropertiesToThreadSafe()Use
CancellationTokenfor responsive shutdown during connection attempts
Step 3: Build the Communication Loop
The CommunicationLoop method runs repeatedly on the background thread after connection is established:
Key concepts:
GetInputsForPLC(): Returns all input signal values as
Dictionary<string, object>SetOutputsFromPLC(): Updates output signals with received data
Signal metadata: Use
TryGetSignalMetadataSafe<T>()to access signal configuration safely from background threadError handling: Use try/catch and ThreadSafeLogger for robust error reporting
Step 4: Handle Signal Exchange
FastInterface provides two main methods for signal data exchange:
Performance optimization:
Use
OnlyTransmitChangedInputs = truein Inspector to only send changed input signalsAccess this setting thread-safely with
threadSafeOnlyTransmitChangedInputsUse appropriate data types - FastInterface handles conversion automatically
Step 5: Implement Connection Cleanup
The CloseConnection method runs on the background thread when stopping communication:
Advanced Features
Using Signal Metadata for Protocol Mapping
Signal metadata allows you to store protocol-specific configuration with each signal:
Dynamic Signal Import
You can create and update signals dynamically using the signal management API:
Thread-Safe Property Access
For Inspector properties that need background thread access, copy them to thread-safe fields:
Best Practices
Performance Optimization
Use change detection for input signals:
Cache signal metadata for better performance:
Batch operations when possible:
Thread Safety Guidelines
Never access Unity GameObjects from background thread methods (
EstablishConnection,CommunicationLoop,CloseConnection)Use ThreadSafeLogger instead of Debug.Log in background threads:
Copy Inspector properties to thread-safe fields:
Use thread-safe signal metadata access:
Error Handling and Debugging
Comprehensive error handling:
Enable debug mode for detailed logging:
Monitor connection state in Inspector:
State: Shows current connection status with visual indicators
CycleCount: Number of communication cycles completed
CommCycleMs: Actual communication timing
ErrorMessage: Last error message if connection failed
Testing Your Interface
Start with the blueprint - copy
BlueprintFastInterface.csfor a working foundationTest connection logic first:
Add simulation mode for testing without external hardware:
Troubleshooting
Common Issues
Interface doesn't connect:
Check network connectivity and firewall settings
Verify IP address and port configuration
Look for error messages in Unity Console and Interface Inspector
Test with external tools (telnet, protocol-specific clients)
Signals not updating:
Verify signals are child objects of the interface GameObject
Check signal directions (Input vs Output)
Enable Debug Mode for detailed signal logging
Ensure metadata mapping is correct
Performance issues:
Enable
OnlyTransmitChangedInputsto reduce network trafficIncrease
UpdateCycleMsif communication is too frequentUse batch operations instead of individual signal writes
Check for blocking operations in CommunicationLoop
Threading errors:
Never access Unity GameObjects from background thread methods
Use ThreadSafeLogger instead of Debug.Log in background threads
Copy Inspector properties to thread-safe fields
Use thread-safe metadata access methods
Debug Tools
Inspector debugging:
Enable Debug Mode for detailed logging
Monitor State field for connection status
Check ErrorMessage for failure details
Watch CycleCount and CommCycleMs for performance
Console logging:
Signal state monitoring:
FastInterface API Reference
FastInterface provides several high-performance helper methods for signal operations in your custom implementations. These methods are available through extension methods and provide thread-safe, optimized signal access.
Signal Value Operations
Batch Signal Operations
Signal Discovery and Management
Thread-Safe Metadata Access
Dynamic Signal Creation
Signal Manager Utilities
Common Usage Patterns
Pattern 1: Metadata-Based Protocol Mapping
Pattern 2: Dynamic Signal Import
Pattern 3: High-Performance Communication
Last updated