I am encountering a strange issue where my Unity Network Manager client and host are starting properly, and a relay is created. However, the client is unable to connect consistently. I have logged the RelayServerData on both the client and server, and they have the same Endpoint and IsSecure values. I am running the host on Unity Editor on Mac and the client on an Android device, Meta Quest 2.
Here are some additional details:
All packages are up to date.
On the host side, I am setting the RelayServerData using the following code:
Despite the similarities in configuration, the client fails to connect to the server most of the time, resulting in a “failed to connect to server” error. However, it successfully connects around 20% of the time, which adds to the confusion.
I would appreciate any insights or suggestions to help resolve this issue.
How much time elapses between the allocation being created, and host/client being started? Allocations on which there is no activity for a few seconds will automatically timeout, so I’d recommend only creating the allocations once you’re about to start the host/client (once started they’ll keep the allocation alive on their own). Also related to that: what’s the value of the heartbeat timeout setting of the Unity Transport component?
Otherwise, do you get the same behavior if connecting with UDP instead of DTLS? You can test that by changing the “dtls” string to “udp”.
With DTLS, I do everything immediately in this order.
Create Allocation on the host → immediately start the host.
Immediately switch device → then join allocation and start the client.
Heartbeat Timeout MS = 500
Connection Timeout MS = 1000
On a side note,
I was earlier getting an error on client, 30% times, while joining the allocation.
“Join Relay Error Unity.Services.Relay.RelayServiceException: Not Found: join code not found —> Unity.Services.Relay.Http.HttpException`1[Unity.Services.Relay.Models.ErrorResponseBody]: (404) HTTP/1.1 404 Not Found“
Despite, the relay code and the code length being the same on the host and client.
I temporarily fixed it by changing the Heartbeat Timeout from 500 to 5000.
Strange that increasing the heartbeat timeout would resolve the 404 error. This would normally lead to less frequent heartbeats and thus a higher probability of an allocation timeout.
What editor version are you using? Also, what’s the version of the Unity Transport package?
Since you’re on 2022.2, you may want to try updating Unity Transport to 2.0.1. You can specify the version when installing by name (or just modify the package manifest directly). There were a lot of changes and improvements in how we handle DTLS and Relay so that might help.
I am not getting the earlier errors, “Not Found: join code not found” and “failed to connect to server”
But sometimes, whenever I run the host on Android (Quest 2), as soon as the client on Unity editor connects to the host, the app on the host crashes without any logs. I will have to check it. I am getting so many random and non-consistent errors with Relay and Unity Transport. Idk
If you can get logs for the crash (here’s how to find them), that’s something I’d definitely be interested in having a look at. There was also a report recently of someone encountering errors due to Burst that were fixed by updating to 2022.2.21. Might be worth a try if you’re able to update.