I am trying to handle errors received by a UNET (new Unity3D networking) client. The below code successfully connects to a server when it is present, but obviously gives a timeout error when there is no server present.

I am trying to determine which type of error was received by the OnError callback method. MsgType is equal to MsgType.Error, which isn't specific, and all of the Read functions I have tried do not return valid data. At minimum I would like to be able to print the same error that prints to the debug log in a location the player can see it.

public class TestClient: MonoBehavior {

    private NetworkClient client;

    void Start () {
        client = new NetworkClient();
        client.Connect("", 1234);
        client.RegisterHandler(MsgType.Error, OnError);

    public void OnError(NetworkMessage netMsg) {

        //Read netMsg here somehow

        Debug.Log("Failed to connect to server");

Note: This code is a retyped copy the working code, so there might be a typo or twenty. It also takes 15-30 seconds to throw the error (I didn't time it).


You must include read it as an ErrorMessage from the UnityEngine.Networking.NetworkSystem namespace.



Note: It is amazing how fast you can find an answer AFTER posting to stackexchange.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.