Hi.
I am struggling to understand and make the SyncEvent functionality work. The idea is to have one class running only on the server, sending events to all clients.
I have a class MyScenario, defining a SyncEvent:
public class MyScenario : NetworkBehaviour {
// set up network events
public delegate void SetTimestep(int newTimestep);
[SyncEvent]
public event SetTimestep EventSetTimestep;
and trigger this event in a timer:
private IEnumerator MyTimer()
{
while(true)
{
yield return new WaitForSeconds(0.2f); // wait half a second
// do things
EventSetTimestep (m_time++);
}
}
In another class I subscribe to this event in the Start function:
public class MyData : NetworkBehaviour{
void Start () {
// subscribe to events
if (myScenario) {
myScenario.EventSetTimestep += setTimestep;
}
}
This works perfect for local player on the host, but not for LAN clients ( I am testing this on only one PC running both HOST and LAN Client). The code for subscribing is called without errors, but the setTimestep method is never called in the LAN client.
Both classes are based on NetworkBehaviour and have NetworkIdentity, but I do not understand completely how to setup the code so that MyScenario only runs on the server. Also the setting for the check-boxed on the NetworkIdentity (Server only / Local Player Authority) is not clear to me.