4.8 KiB
Quick Fix Guide for "Failed to Connect to Server"
Your Issue: Teammate sees "CONNECTED" but can't join
This is likely a Firewall issue even with port forwarding.
Immediate Actions (Try in Order)
1. Disable Windows Firewall Temporarily (Test Only)
Windows Security → Firewall & network protection → Private network → Microsoft Defender Firewall: OFF
Public network → Microsoft Defender Firewall: OFF
Then test connection. If it works, re-enable and create specific rule for Unity.
2. Add Unity Exclusion to Firewall
Run these commands as Administrator in PowerShell/CMD:
# Allow Unity Editor
netsh advfirewall firewall add rule name="Unity Editor" dir=in action=allow program="%ProgramFiles%\Unity\Hub\Editor\*\Unity.exe" enable=yes
# Allow your built executable (replace 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
3. Verify Port Forwarding is Working
Go to: https://www.yougetsignal.com/tools/open-ports/
- Enter your PUBLIC IP (what you give to teammate)
- Enter port 7777
- Click "Check Port"
Expected: "Port 7777 is open on [YOUR PUBLIC IP]" If closed: Port forwarding is incorrect
4. Add Debug Scripts to Scene
Add these components to your NetworkManager GameObject:
- ConnectionDiagnostics - Checks for configuration issues
- NetworkDebugger - Shows detailed connection logs
- NetworkConnectionFixer - Fixes common timeout issues
Right-click each and select "Run Diagnostics" or "Fix All Known Issues"
What to Check in Console
Host Should See:
✓ [NetworkConnectionFixer] Network fixes applied
✓ [ConnectionDiagnostics] System Healthy
✓ [NetworkDebugger] Server Started Successfully
✓ [NetworkDebugger] Listening on: 0.0.0.0:7777
✓ [NetworkDebugger] Client Connected: [ID]
✓ [ConnectionHandler] 클라이언트 [ID] 승인됨. 수동 스폰으로 대기.
Client Should See:
✓ [NetworkConnectionFixer] Network fixes applied
✓ [ConnectionDiagnostics] System Healthy
✓ [NetworkDebugger] Connection Approval Request from Client [ID]
✓ [NetworkDebugger] Approval Response: Approved: true
If Still Not Working
Check These Settings:
On NetworkManager GameObject:
- Player Prefab assigned
- Network Prefabs list populated
- Transport component = Unity Transport (UTP)
On Unity Transport Component:
- ConnectionData.Port = 7777 (or your port)
- ConnectionData.Address = 0.0.0.0 for Host
- Connect Timeout MS = 15000
- Max Connect Attempts = 10
In NetworkManager Inspector (Network Config):
- Connection Approval = checked
- Enable Scene Management = checked
Common Mistakes
❌ Using 127.0.0.1 or 192.168.x.x for teammate ✓ Use your PUBLIC IP for teammate
❌ Firewall blocking Unity ✓ Add exception for Unity and your game
❌ Port not actually forwarded ✓ Verify with online port checker
❌ Wrong transport address on host ✓ Host should use 0.0.0.0, client uses YOUR public IP
❌ Player prefab missing NetworkObject ✓ Ensure player prefab has NetworkObject component
Quick Test Sequence
-
Test Local:
- Start Host (connect to 127.0.0.1 from same instance)
- If this fails: Project setup issue
-
Test LAN:
- Use 192.168.x.x (local network IP)
- If this fails: Network/Firewall issue
-
Test Internet:
- Use public IP
- If this fails: Port forwarding issue
Console Commands for Diagnostics
Add this to a MonoBehaviour:
[ContextMenu("Check Everything")]
void CheckEverything()
{
Debug.Log("IsServer: " + NetworkManager.Singleton.IsServer);
Debug.Log("IsClient: " + NetworkManager.Singleton.IsClient);
Debug.Log("ConnectedClients: " + NetworkManager.Singleton.ConnectedClients.Count);
Debug.Log("Local IP: " + NetworkUtility.GetLocalIPv4());
}
Last Resort Solutions
-
Use VPN/Hamachi
- Creates virtual LAN between you and teammate
- No port forwarding needed
- Both connect to VPN IP
-
Use Unity Relay
- Built into Unity Netcode
- Bypasses NAT/Firewall completely
- Requires Unity Services account
-
Host on Cloud Server
- AWS/Azure/Google Cloud
- Static IP, no port forwarding
- More reliable
Share These for Help
If still broken, share:
- Full Console log (Host and Client)
- Screenshot: NetworkManager inspector
- Screenshot: Unity Transport settings
- Port checker result screenshot
- Windows Firewall rules screenshot
Most likely issue: Windows Firewall is blocking even with port forwarding. Fix: Run firewall commands in step 2.