4.9 KiB
4.9 KiB
Connection Issue: Immediate Action Plan
Your Problem
Teammate sees "CONNECTED" but gets "Failed to connect to server" error.
Root Cause (Most Likely)
Windows Firewall is blocking Unity/Build even with port forwarding done correctly.
FIX IN 3 STEPS
Step 1: Add Debug Components (1 minute)
Add these to your NetworkManager GameObject in BOTH Host and Client scenes:
- ConnectionDiagnostics (automatic check)
- NetworkDebugger (detailed logs)
- NetworkConnectionFixer (auto-fixes issues)
Step 2: Fix Firewall (2 minutes)
Run PowerShell as Administrator, paste this:
# Allow Unity Editor
netsh advfirewall firewall add rule name="Unity Editor" dir=in action=allow program="C:\Program Files\Unity\Hub\Editor\*\Unity.exe" enable=yes profile=any
# Allow your game build (update path!)
netsh advfirewall firewall add rule name="Northbound Game" dir=in action=allow program="D:\Northbound\Build\Northbound.exe" enable=yes profile=any
# Allow port 7777
netsh advfirewall firewall add rule name="Unity Port 7777" dir=in action=allow protocol=TCP localport=7777 enable=yes profile=any
Step 3: Verify Port Forwarding (1 minute)
Go to: https://www.yougetsignal.com/tools/open-ports/
- Enter your PUBLIC IP
- Enter port 7777
- Should say: "Port 7777 is open"
If "Closed", your router port forwarding is wrong.
Quick Diagnostics
In Unity Editor (Play Mode):
- Add ConnectionDiagnostics to NetworkManager
- Right-click component → "Run Diagnostics"
- Check console for errors/warnings
Common Diagnostics Results:
- ✅ "System Healthy": Configuration is good, issue is network/firewall
- ⚠️ "Player Prefab NOT assigned": Assign player prefab in NetworkManager
- ⚠️ "Connect timeout too low": ConnectionDiagnostics fixes this automatically
- ❌ "NetworkManager not found": Add NetworkManager to scene
If Still Not Working:
Test 1: Local Connection
Host connects to 127.0.0.1 (same instance)
- ✅ Works = Good setup, issue is network
- ❌ Fails = Project setup issue
Test 2: LAN Connection
Host shares 192.168.x.x IP (same WiFi)
- ✅ Works = Good LAN, issue is port forwarding for internet
- ❌ Fails = Firewall blocking local connections
Test 3: Internet Connection
Host shares PUBLIC IP with teammate
- ✅ Works = Fixed!
- ❌ Fails = Port forwarding or remote firewall
What Console Should Show
Host (Working):
[ConnectionDiagnostics] System Healthy
[NetworkConnectionFixer] Network fixes applied
[NetworkDebugger] Server Started Successfully
[NetworkDebugger] Listening on: 0.0.0.0:7777
[NetworkDebugger] Client Connected: 1
[ConnectionHandler] 클라이언트 1 승인됨
[ConnectionHandler] 플레이어 1 스폰됨
Client (Working):
[ConnectionDiagnostics] System Healthy
[NetworkConnectionFixer] Network fixes applied
[NetworkDebugger] Connection Approval Request
[NetworkDebugger] Approval Response: Approved: true
[NetworkDebugger] Client Connected: 0
Client (Broken - Your Case):
[ConnectionDiagnostics] System Healthy
[NetworkConnectionFixer] Network fixes applied
[NetworkDebugger] Connection Approval Request
<color=red>[NetworkDebugger] TRANSPORT FAILURE!</color>
Failed to connect to server
Tools Created for You
| File | Purpose | How to Use |
|---|---|---|
| ConnectionDiagnostics.cs | Auto-checks configuration | Add to scene, right-click "Run Diagnostics" |
| NetworkDebugger.cs | Shows detailed connection logs | Add to scene, watch Console during connection |
| NetworkConnectionFixer.cs | Fixes common timeout issues | Add to scene, right-click "Fix All Known Issues" |
| PublicIPHelper.cs | Gets your public IP automatically | Add to scene, see Inspector |
Most Likely Issue: Firewall
Even with correct port forwarding, Windows Firewall blocks:
- ✅ Port 7777 may be open (router allows it)
- ❌ But Windows Firewall blocks the application using that port
Solution: Allow Unity and your game through firewall (Step 2)
Alternative: Use Hamachi/VPN
If port forwarding is too complex:
- Both install Hamachi: https://www.vpn.net/
- Join same Hamachi network
- Use Hamachi IP (25.x.x.x) instead of public IP
- No port forwarding needed!
Share This for Help
If issue persists, share screenshots/logs:
- ✅ NetworkManager Inspector (screenshot)
- ✅ Unity Transport settings (screenshot)
- ✅ Console log (Host) - after connecting
- ✅ Console log (Client) - after connection attempt
- ✅ Port checker result (screenshot)
- ✅ Windows Firewall rules list (screenshot)
Summary
- Add debug components (1 min)
- Fix firewall (2 min) - MOST IMPORTANT
- Verify port forwarding (1 min)
- Test with console logs
If all this fails, the issue is likely:
- Port forwarding is wrong (verify with online tool)
- Different Unity/Netcode versions between you and teammate
- Antivirus/security software blocking
Good luck! 🎮