- Home /
OnReceivedBroadcast not being called with Network Discovery
I have written the following code for automatically connecting to a LAN game. A pair of buttons call startLanHost and startClient. When running two builds of the game OnReceivedBroadcast is never called by a client. Is my code not written correctly?
public class NetworkConnector : NetworkDiscovery {
public NetworkManager networkManger;
public bool gameFound;
public bool lookingForGame;
public string networkAddress;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (lookingForGame && gameFound)
{
networkManger.StartClient();
}
}
public void startLanHost()
{
Initialize();
networkManger.StartHost();
StartAsServer();
}
public void startClient()
{
Initialize();
StartAsClient();
lookingForGame = true;
}
public override void OnReceivedBroadcast(string fromAddress, string data)
{
Debug.Log("Revcieved broadcast");
networkManger.networkAddress = fromAddress;
gameFound = true;
}
}
Answer by HunterZero45 · Jul 14, 2016 at 04:36 AM
It seems than the NetworkDiscovery's Update() Function is doing something to call OnReceivedBroadcast, if you use Update() in the child class, the base Update() won't be called.
You can try your own code in LateUpdate() or somewhere else.
Normally we do StartClient just in OnReceivedBroadcast(), and no need to use Update().
Hope it can help you.
Your answer
Follow this Question
Related Questions
Unet Timeout Issues 4 Answers
UNet - Change scene in LAN 1 Answer
How to Connect() in LAN, not working? 1 Answer
Unet LAN Connection Function 0 Answers
how can i pickup a weapon and drop it on certain key press?(unet) 0 Answers