-1

I actually use Unet for Unity and when a client try to join using a bad IP, I have a timeOut Error.

Error of Unity when the server is turn-off

I would like to avoid this timeOut error. So, I tried to override the "OnDisconnectClient" of NetworkManager.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class CustomNetworkManager : NetworkManager {

    public override void OnClientDisconnect(NetworkConnection conn)
    {
       Debug.Log("TimeOutError"); 
    }
}

It works, but this function is also called when the client quit the server on purpose. So I tried this :

public class CustomNetworkManager : NetworkManager {

    public override void OnClientDisconnect(NetworkConnection conn)
    {
        try
        {
            base.OnClientDisconnect(conn);
        }
        catch(Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
}

But the error isn't catch and still pop in the console. I also tried catch without the Exception parameter but still the same.

Thanks per advance for the help.

PS: I work on Unity 2018.2.15f1

Community
  • 1
  • 1
Studio Pie
  • 21
  • 4
  • 1
    Please add code as code, not as image. – Rene Knop Nov 27 '18 at 16:02
  • Edited just now, it's now code. – Studio Pie Nov 27 '18 at 16:17
  • using `try - catch` inside of `OnClientDisconnect` won't help much since this is not the method trowing the error. It is not the disconnect that has a timeout but the connect. Maybe [this](https://gamedev.stackexchange.com/questions/105451/unet-error-handling) helps? – derHugo Nov 29 '18 at 21:17
  • @derHugo thanks for your answer. I tried the answer on your link but I did'nt get much more.. Also I don't get it, If the error isn't thrown by the `OnClientDisconnect`, why overriding it removes the error? – Studio Pie Nov 30 '18 at 13:24

1 Answers1

0

I would use a try-catch statement, to catch the exception. then in the catch do what ever error handling you want to do.

  • Thanks, I tried this but it doesn't work, don't know why... Updated my post to add the code I tried. – Studio Pie Nov 28 '18 at 08:59
  • i notice that you code is printing the error in the console, could this be why it still appears in the console? Also could it be that the error is happening in the OnClientDisconnect() method, for if it is than your try catch statement would need to be in the base method. – Isaac Newton Nov 29 '18 at 15:16
  • Isn't it the purpose of the try-catch statement? To catch the error thrown by the called method? – Studio Pie Nov 30 '18 at 13:20
  • Have you tried putting the specific exception in the try-catch so that it specifically looks for that error – Isaac Newton Dec 08 '18 at 03:01