Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Error Handling in UNET

Discussion in 'UNet' started by diesen1, Aug 8, 2015.

  1. diesen1

    diesen1

    Joined:
    Jul 3, 2014
    Posts:
    15
    how can I get the error text and code in unity networking,?

    I did the following:
    1- subscribe to the Handler : Client.RegisterHandler(MsgType.Error, OnError);
    2- create the handler
    void OnError(NetworkMessage netMsg)
    {
    how can I print the ERROR message here
    }
     
  2. l3fty

    l3fty

    Joined:
    Mar 23, 2013
    Posts:
    86
    Usually you would do something like:
    ErrorMessageType errorMsg = netMsg.ReadMessage<ErrorMessageType>();

    And then you could get at the information in that message. Though I can't find any reference to the class Unity would associate with MsgType.Error. It's possibly something they haven't exposed. Other kinds of messages use a class we define ourselves ontop of MessageBase. Hopefully someone else knows more, as it sure would be useful to get at :D
     
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  4. GunLengend

    GunLengend

    Joined:
    Sep 24, 2014
    Posts:
    52
    It's said ErrorMessage doesn't contain in current context ?
     
    perevezentsev likes this.
  5. saadminhas

    saadminhas

    Joined:
    Jul 3, 2012
    Posts:
    2
    I have been trying to implement a function which upon failing to connect to the server takes the user to a different scene.
    I have managed to implement the above code, and everything works fine, i can get the messages upon failing to connect.
    But i just can't make my code to do anything else(change the scene) instead of just delivering messages.

    Any assistance would be highly appreciated..
     
  6. carterdawson

    carterdawson

    Joined:
    Jan 18, 2014
    Posts:
    5
    I just ran across this, and it looks like it wasn't resolved, and I suffered through the same problem.

    You need to use UnityEngine.Networking.NetworkSystem:

    using UnityEngine.Networking.NetworkSystem;

    ...

    Debug.Log("Client: OnError: " + netMsg.ToString());
    ErrorMessage mess = netMsg.ReadMessage<ErrorMessage> ();
    owner.OnGameError ("Failed to connect: " + ((NetworkError)mess.errorCode).ToString());

    Why is mess.errorCode an int and not a NetworkError? Who knows?

    Shaun
     
    perevezentsev likes this.
unityunity