I am trying to check some events like when a client connects to a game or disconnects and so on. for now I have been testing with this script, but it doesnt seem to fire the event when a client connects.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class TestNetworkManager : NetworkManager
{
public override void OnClientConnect(NetworkConnection conn)
{
Debug.Log("New client connected");
}
}
Anyone has an idea how to check for network events (in an easy way )?
Still nothing happens. I am using the default Network Manager HUD script included in Unity and I am hosting a local game. So I expected this event to fire anyway, since I should be Server and Client at the same time, right? But when I host a game non of these fire.
I just checked what happens if I build the game and connect with an additional client and then OnServerConnect seems to fire. So how can I check if the host connects? Is there any event as well?
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class TestNetworkManager : NetworkManager
{
void start()
{
Debug.Log("started");
}
public override void OnServerConnect(NetworkConnection conn)
{
Debug.Log("New client connected, ID: " + conn.connectionId.ToString());
}
public override void OnServerDisconnect(NetworkConnection conn)
{
Debug.Log("Client disconnected, ID: " + conn.connectionId.ToString());
}
public override void OnClientConnect(NetworkConnection conn)
{
Debug.Log("Connected to Server.");
}
public override void OnClientDisconnect(NetworkConnection conn)
{
Debug.Log("Disconnected from Server.");
}
}
But the last two events just never fire. I built my project and started a server with the exe file and connected via the editor. Still no message in the console.
Okay I now found the error, after thinking and trying for hours, haha. The problem was, that the online level was loaded so quick after joining, that the NetworkManager seems to have not been able to fire any event before the new scene was loaded. After removing the online scene from the NetworkManager (for testing) it fires the OnClientConnect event without any problems.