Search Unity

Unity Multiplayer [SyncEvent] vs [ClientRpc]

Discussion in 'Multiplayer' started by liortal, Jun 13, 2015.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,506
    Hi,

    I just read about the [SyncEvent] attribute and i was wondering why is it needed?

    According to the docs (http://docs.unity3d.com/Manual/class-NetworkBehaviour.html)
    What would be the difference between having an RPC method on clients that invokes an event vs. using a [SyncEvent] ? are both of these the same ?

    If so, why is this additional attribute needed ?
     
  2. samfarhan

    samfarhan

    Joined:
    Oct 14, 2012
    Posts:
    14
    SyncEvents let you register to the event that will be called from anywhere whereas a ClientRPC will only be called on the same NetworkBehaviour and you can't register to it like an event.
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,506
    Not sure i follow what's the difference...

    can't i achieve event registration also with ClientRpc, e.g - expose an Rpc method that raises an event:
    Code (CSharp):
    1. public class TestBehaviour : NetworkBehaviour
    2. {
    3.     public event System.Action TestEvent;
    4.  
    5.     [ClientRpc]
    6.     public void RpcTest()
    7.     {
    8.         // Call this event
    9.         TestEvent();
    10.     }
    11. }
     
  4. samfarhan

    samfarhan

    Joined:
    Oct 14, 2012
    Posts:
    14
    You can but that seems completely pointless when it is essentially what SyncEvents do.

    From what I understand of the docs, SyncEvents are basically RPC's except they have events built into them to make your life a little easier.
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,506
    And my point was that SyncEvents are pointless since you can achieve the same like i showed. The typing it saves is absolutely minimal in this case... unless i got it all wrong and they have some other purpose.
     
    Last edited: Jun 14, 2015
  6. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
    Let's be honest if you want to say that you don't need convenient functions to do specific things because you could do them other ways as well we might as well just get rid of all these convenience attributes and do everything with the Network Messaging System.
     
    omeys likes this.
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,506
    I am not saying "let's get rid of all the little convenience functions". I am asking why do we need 2 things to do the same thing just for minimal extra typing.

    For example, the [SyncVar] attribute saves a lot of typing by generating code, managing the dirty bitmask and calling the relevant serialization methods for the NetworkBehaviour type for you. This is a good example of something that is beneficial for the developer; but having 2 options that do almost the same thing, just for saving 1 line of code seems odd to me.

    That's just my opinion of course.
     
    Last edited: Jun 15, 2015
    isidro02139 likes this.
  8. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    I actually kind of agree. SyncEvent has turned out to not be very useful. A fully networked version of the UnityEvent system that was introducted with uGui that understands distributed authority would be useful, but SyncEvent as it stands is far from that.
     
unityunity