- Home /
Network OnServerStart
I have a problem with a networkmanager and a networkbehaviour.
NetworkManager:
public class NM : NetworkManager {
void Start() {
NetworkManager.singleton.StartHost();
}
}
NetworkBehaviour:
public class NB : NetworkBehaviour {
void OnServerStart() {
Debug.Log("Server Started.");
}
}
But "Server started." is never printed to the log. How would I make the OnServerStart work in the second script?
Answer by seanr · Aug 26, 2015 at 07:40 PM
in class NB use:
public override void OnStartServer()
{
Debug.Log("Server Started.");
}
But the public override void OnStartServer() can only be called in a script that derives from Network$$anonymous$$anager?
The method "OnStartServer()" is part of both Network$$anonymous$$anager as well as NetworkBehaviour but they have different meanings. When OnStartServer is fired on Network$$anonymous$$anager, it means a new server has started (fired for both host servers and dedicated servers).
The OnStartServer in NetworkBehaviour is fired when an object is spawned across the network. You can think of this method as the regular "Start()"-method of a $$anonymous$$onoBehaviour, but it is only fired server-side after spawning an object. The counterpart of OnStartServer is OnStartClient, which is fired on the object by the client when the object is spawned across the network.