Synchronized Event, or most commonly referred as "SyncEvent" are easily definable in your code, and will handle automatically calling events to all players listening to the event.
Working with SyncEvent is as easy as using a regular UnityEvent, only having to be mindful of who has authority.
SyncEvents are built with the Network Module setup, meaning that you have to initialize it. Below is a usage example:
//Creates an instance of the event - True means that it is owner authority[SerializeField] privateSyncEvent<int> syncEvent =new(true);protectedoverridevoidOnSpawned(){ //Listening to the eventsyncEvent.AddListener(SyncEventTest);}privatevoidSyncEventTest(int myValue){ //Everyone subscribed to the syncEvent will receive this value when the owner invokes itDebug.Log($"Received value: {myValue} from SyncEvent");}publicvoidInvokeSyncEvent(){ //Because the event is owner auth, only the owner can call the event.if (!isOwner)return; //Invoking the event as the owner with the value 10syncEvent.Invoke(10);}
The SyncEvent is serializable in the Unity editor as a Unity Event, meaning that you can easily add events straight from the inspector view.