Handling Connection Errors

Has anyone got any pointers on how to handle connection errors on initial connect?

If I run StartClient, the return value isn't trustworthy, Unity Transport returns true even on failure to start the client and connect. UNetTransport at least responds accurately here with false.

However, both transports output errors into the log, but neither seem to return these errors, or throw them as exceptions to catch; they just catch them and silently fail.

Is there really no way to capture connection failure errors? Is it really a case of having to just run a timer and if we're not connected by a certain time then throw a generic error to the user with no hint as to what's happened as in the Boss Room example?

To be clear about what I'm saying, it's easy to test - run start client against a non-existent address, with each transport you'll get an error, but neither passes that error upto the caller of StartClient as far as I can tell.

Am I missing something obvious here or does NetCode for GameObjects just have no error response for things like connection errors?

I'd love an answer on this one too. I'm really surprised by the lack of exception throwing.

please, I'm dealing with this issue as well, any help would be appreciated!

Before calling StartClient, on loading your connection script (e.g. in OnEnable) subscribe to OnClientDisconnectCallback. For example, write a function called HandleClientDisconnected:


This function will be called when a client successfully connected and then disconnected, but also when the connection failed for any reason (e.g. invalid address, timeout). By setting a local variable on successful connection, you can distinguish between these two cases.

CosmoM thank you for saving my day