4.1 KiB
4.1 KiB
Local Testing Setup Guide
Testing Both Players in Same Scene
When testing the UDP avatar sync system with both broadcaster and receiver in the same Unity scene, you need to handle port conflicts properly.
The Port Conflict Issue
The error you encountered:
Failed to start UDP listener: Only one usage of each socket address (protocol/network address/port) is normally permitted.
This happens because both components try to bind to the same UDP port (8080) simultaneously.
Solution: Updated Receiver with Port Sharing
The UDPAvatarReceiver has been updated with port sharing capabilities:
New Settings in Inspector
- Allow Port Sharing: ✅ Enable this for local testing
- Listen Port: 8080 (or will auto-find alternative)
How It Works
- Port Sharing Enabled: Uses
SO_REUSEADDRsocket option to allow multiple bindings - Fallback Ports: If port sharing fails, tries ports 8081, 8082, 8083, etc.
- Debug Info: Shows actual port being used in the GUI
Local Testing Setup
GameObject 1: Player 1 (Broadcaster + Receiver)
Avatar Player 1
├── UDPAvatarBroadcaster
│ ├── Player ID: 1
│ ├── Avatar Root: [Player 1 Avatar]
│ └── Show Debug Info: ✅
└── UDPAvatarReceiver
├── Target Player ID: 2 (receive from Player 2)
├── Target Avatar Root: [Player 2 Avatar Clone]
├── Allow Port Sharing: ✅
└── Show Debug Info: ✅
GameObject 2: Player 2 (Broadcaster + Receiver)
Avatar Player 2
├── UDPAvatarBroadcaster
│ ├── Player ID: 2
│ ├── Avatar Root: [Player 2 Avatar]
│ └── Show Debug Info: ✅
└── UDPAvatarReceiver
├── Target Player ID: 1 (receive from Player 1)
├── Target Avatar Root: [Player 1 Avatar Clone]
├── Allow Port Sharing: ✅
└── Show Debug Info: ✅
Alternative Setup Methods
Method 1: Different Ports (Simple)
- Player 1 Broadcaster: Port 8080
- Player 2 Broadcaster: Port 8081
- Update receivers to listen on corresponding ports
Method 2: Single Broadcaster (Minimal)
- One broadcaster component sending data
- Multiple receivers in scene listening
- Good for testing receiver logic only
Method 3: Separate Scenes (Real-world)
- Build and run multiple instances of your game
- Most accurate representation of real multiplayer
Troubleshooting
Still Getting Port Errors?
-
Check Windows Firewall:
Allow Unity.exe through Windows Defender Firewall Allow UDP port 8080-8085 -
Verify Port Sharing Setting:
UDPAvatarReceiver → Allow Port Sharing: ✅ -
Check Console for Alternative Ports:
Look for: "UDP listener started on alternative port 8081"
No Data Being Received?
-
Verify Player IDs:
- Broadcaster Player ID: 1
- Receiver Target Player ID: 1 (to receive from broadcaster)
-
Check Debug GUI:
- Broadcaster: "Broadcasting" status
- Receiver: "Listen Port" shows actual port
-
Test Loopback:
- Set Receiver Target Player ID: 0 (receive from any)
- Should receive own broadcasts
Debug Information
Enable debug info on both components to see:
Broadcaster GUI (Top-left):
- Player ID and broadcast status
- Sequence number (should increment)
- Update rate and packet size
Receiver GUI (Top-right):
- Listen port (actual port being used)
- Packets received/dropped
- Target player ID
Production vs Testing
| Environment | Setup | Port Handling |
|---|---|---|
| Local Testing | Same scene, port sharing | Allow Port Sharing: ✅ |
| LAN/Hotspot | Separate devices | Standard UDP binding |
| Production | Different machines | No port conflicts |
Quick Checklist
- ✅ Enable "Allow Port Sharing" on all receivers
- ✅ Set unique Player IDs (1, 2, 3...)
- ✅ Set correct Target Player IDs on receivers
- ✅ Enable debug info to monitor status
- ✅ Check console for port conflict messages
- ✅ Verify Windows Firewall allows Unity/UDP
The updated receiver should now handle local testing scenarios gracefully!