OnStopHost override is running Twice

Why on earth do i get two of the same function happening.

When i start the app and Host, then click the disconnect button, i get the OnStopHost override method happening 2 times. This only happens on the first time Hosting in the current session. Any times hosting beyond that it only fires once.

Debug.Log 1
Implement OnStopHost Operations Here
UnityEngine.Debug:Log(Object)

Debug.Log 2
Implement Stop Host operations here.
UnityEngine.Debug:Log(Object)

Debug.Log3
Implement OnStopHost Operations Here
UnityEngine.Debug:Log(Object)

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;

public class A3DNetworkManager : NetworkManager {

    NetworkClient nClient = new NetworkClient();

    public Canvas[] gameMenuItems;

    private void Awake()
    {
        inputField_ServerIP.onValueChanged.AddListener(InputField_ServerIPChanged);
        //logLevel = LogFilter.FilterLevel.Developer;
        autoCreatePlayer = false;
    }

    private void Start()
    {

    }

    private void Update()
    {

    }







    public override void OnStartHost()
    {
        Debug.Log("Implement OnStartHost Operations Here");
    }

    public void OnStartClient()
    {
        Debug.Log("Implement OnStartClient Operations Here");
    }

    public void OnStartServer()
    {
        Debug.Log("Implement  OnStartServer Only Operations Here");
    }

    public override void OnStopHost()
    {
        Debug.Log("Implement OnStopHost Operations Here");
    }

    public void OnStopClient()
    {

    }

    public void OnStopServer()
    {

    }



    public void OnClientReadyMessage()
    {

    }







    public void StartLANHost()
    {
        gameMenuItems[0].enabled = false;
        gameMenuItems[1].enabled = true;
        nClient = StartHost();
        Debug.Log("Implement Start Host operations here.");
    }

    public void StopLANHost()
    {
        gameMenuItems[1].enabled = false;
        gameMenuItems[0].enabled = true;
        Shutdown();
        Debug.Log("Implement Stop Host operations here.");
    }

    public void StartLANClient()
    {
        nClient = StartClient();
        Debug.Log("Implement Start Client operations here.");
    }

    public void StopLANClient()
    {
        Shutdown();
    }

    public void StartServerOnly()
    {
        Debug.Log("Implement Start Server operations here.");
    }

    public void StopServerOnly()
    {

    }

    public InputField inputField_ServerIP;
    public void InputField_ServerIPChanged(string _serverIP)
    {
        networkAddress = _serverIP;
    }
}

as you can see, i’m just trying to figure out the beginner stuff here, but WHY would that trigger two times? Its odd that if i just hit host again, then disconnect again, only one message from each method is output. But that first time… well, its like magic (to quote the king of pop :eyes:, lol);

I dont use the HLAPI so I dont know if this is normal, but assuming it isnt, calling StopHost as well as Shutdown causes OnStopHost to be called. Are you doing something different the first time you stop? Is there ever a time you are calling both StopHost and Shutdown or maybe you called Shutdown multiple times?

In case you didnt know, you can look at the HLAPI source code here
(This is the 2017.3 unity version) https://bitbucket.org/Unity-Technologies/networking/src/303d5875befe232c4833bbb31d9c918bdcd3c62e/?at=2017.3

Also, many people seem to have issues (bugs) with the HLAPI code, so someone went and tried to fix a lot of it, which you can get the code from here

1 Like

But i dont even make a call to StopHost(). Just shutdown.

Hlapi is so confuzzling

Yea, thanks mate. I browsed over that thread, and its probably really great for the users that know what they are doing, but i think i still have enough issues just figuring out the beginner stuff. Maybe once i get a better understanding of all this I will upgrade to the new libraries hes offering.