5.1 KiB
5.1 KiB
UDP Avatar Sync System
A simplified, efficient replacement for the HTTP/JSON avatar sync system using UDP broadcasting and compact binary data.
Key Improvements
Old System (HTTP/JSON)
- ❌ Required Python server (
avatar_sync_server.py) - ❌ Large JSON payloads (~1792 lines, complex nested objects)
- ❌ HTTP request/response overhead
- ❌ Complex serialization with multiple C# classes
- ❌ All 80+ bones transmitted every frame
- ❌ Inefficient for real-time sync
New System (UDP Broadcasting)
- ✅ No server required - pure peer-to-peer broadcasting
- ✅ Compact binary format - ~670 bytes per packet (vs ~50KB+ JSON)
- ✅ UDP broadcasting - automatic discovery, no IP configuration
- ✅ Priority-based data - only essential bones and facial data
- ✅ Fixed packet size - predictable network usage
- ✅ Real-time optimized - designed for 30-60 Hz updates
Components
UDPAvatarBroadcaster
Captures and broadcasts your avatar data to the local network.
Key Features:
- Selects only priority bones (20 most important)
- Compact binary serialization
- Configurable update rates (1-120 Hz)
- Optional facial blend shape data
- Network performance monitoring
UDPAvatarReceiver
Receives and applies avatar data from other players.
Key Features:
- Multi-threaded UDP listening
- Smooth interpolation options
- Packet loss detection
- Player ID filtering
- Thread-safe data handling
Quick Setup
For Player 1 (Broadcaster)
- Add
UDPAvatarBroadcastercomponent to your avatar - Set
Player IDto1 - Assign your avatar root transform
- Enable broadcasting
For Player 2 (Receiver)
- Add
UDPAvatarReceivercomponent to target avatar - Set
Target Player IDto1(to receive from Player 1) - Assign target avatar root transform
- Enable receiver
For Bidirectional Sync
- Each player needs both components
- Use different Player IDs (1, 2, 3, etc.)
- Set Target Player ID to receive from specific players
Configuration
Network Settings
- Port: 8080 (default, ensure firewall allows UDP)
- Broadcast Address: 255.255.255.255 (local network)
- Update Rate: 30 Hz recommended (balance of smoothness vs bandwidth)
Data Selection
- Priority Bones: 20 essential bones (customizable array)
- Core: Hips, Spine, Neck, Head
- Arms: Shoulders, Arms, Forearms, Hands
- Legs: Upper legs, Legs, Feet
- Facial Data: 10 most important blend shapes
- Root Transform: Position, rotation, scale options
Performance Options
- Smooth Transitions: Interpolate between updates
- Transition Speed: How fast to blend changes
- Debug Info: Network stats and diagnostics
Data Structure
The system uses a fixed binary format:
Header (9 bytes):
- Player ID (1 byte)
- Sequence Number (4 bytes)
- Timestamp (4 bytes)
Root Transform (40 bytes):
- Position (12 bytes: 3 floats)
- Rotation (16 bytes: 4 floats)
- Scale (12 bytes: 3 floats)
Priority Bones (560 bytes):
- 20 bones × 28 bytes each
- Position (12 bytes) + Rotation (16 bytes) per bone
Facial Data (40 bytes):
- 10 blend shape weights (4 bytes each)
Total: ~649 bytes per packet
Network Requirements
- Local Network: All devices must be on same subnet
- Firewall: Allow UDP port 8080 (or configured port)
- Bandwidth: ~20KB/s per player at 30 Hz (very lightweight)
Troubleshooting
No Data Received
- Check firewall settings (allow UDP on chosen port)
- Verify devices are on same network subnet
- Ensure different Player IDs for broadcaster/receiver
- Check Debug Info for network statistics
Performance Issues
- Reduce update rate (try 15-20 Hz)
- Disable smooth transitions for lower latency
- Reduce max blend shapes count
- Check packet loss statistics
Bone Mapping Issues
- Verify bone names match priority bone list
- Check Debug Info to see cached bone count
- Customize priority bones array for your rig
Advanced Usage
Custom Bone Sets
Modify the priorityBones array to match your avatar rig:
private string[] priorityBones = {
"Root", "Spine1", "Spine2", "Head",
"LeftArm", "RightArm",
// Add your specific bone names
};
Multiple Players
- Each broadcaster needs unique Player ID (1-255)
- Receivers can filter by Target Player ID
- Set Target Player ID to 0 to receive from any player
Network Optimization
- Increase update rate for smoother motion (higher bandwidth)
- Decrease update rate for lower bandwidth usage
- Adjust transition speed for different responsiveness
Migration from Old System
-
Remove old components:
- AvatarSyncClient
- AvatarDataUploader
- AvatarDataDownloader
- AvatarDataWriter
- AvatarDataReader
-
Remove server dependency:
- Stop
avatar_sync_server.py - No longer need HTTP endpoints
- Stop
-
Add new components:
- UDPAvatarBroadcaster (for sending)
- UDPAvatarReceiver (for receiving)
-
Configure network:
- Ensure UDP port is open
- Set unique Player IDs
- Test on local network first
The new system is much simpler to set up and requires no server infrastructure!