Search Unity

bug? not receiving RPC on object with local player authority

Discussion in 'Multiplayer' started by robochase, Apr 14, 2017.

  1. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    i've got an object that i spawn with local player authority via NetworkServer.SpawnWithClientAuthority.

    i run an OnStartServer function on that object, where i have the server send an Rpc call so other players can run some initialization code. I am NOT seeing this Rpc call come through for the player with authority - is this intentional behavior? i do see it called for the server's client btw

    i'm on unity 5.3.7...and i haven't tested this with 3 players yet to see if the other clients would get this rpc call or not.
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    RPC's are unrobust/buggy and aren't always received. Even on the host.

    They are only sent to observed clients. So if a client isn't loaded yet, or is in the middle of a scene transition, or for whatever reason the object isn't observed then the RPC's fail.
     
    LadyEbony likes this.
  3. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    thanks, i'll have to look at that part in the UNET code!

    i was tracing the path of my RPC call with some help from ILSpy, and it seems like there's nothing stopping the server from sending the RPC out as normal, but perhaps the client isn't able to map it to the right object since it's happening pretty close to the time it's instantiated. i ended up working around the core problem, but i may end up revisiting this eventually.

    i feel like there's probably something gross going on under the hood. i noticed similar problems with sync vars on this particular object not working too.

    @Zullar if an RPC doesn't always go through, then what is the point of a reliable channel? in your experience, is it more consistent if you just send a network message manually?
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    In my experience SyncVars and ClientRPC are both buggy and unreliable if they are used certain ways. I use NetworkMessage for *everything* now because these bugs have no workarounds. I wouldn't recommend ClientRPC or SyncVar to anybody until these bugs are fixed.

    1: SyncVars can de-sync due to a connecting client (this clears dirty bits and can leave other clients with incorrect values indefinitely until the value is changed marked dirty and re-sent to clients in the future)
    2: SyncVars hooks can fail to be called due to NetworkIdentity.observers dropping off around a scene change (for persistent DontDestroyOnLoad objects)
    3: ClientRPC can fail to be received due to NetworkIdentity.observers dropping off around a scene change (for persistent DontDestroyOnLoad objects)

    Those are the bugs I've found. Are your bugs with SyncVar/ClientRPC's not working occurring around a scene change, or during initialization?
     
  5. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    My bugs (?) happen during initialization of an object. It's basically for a grenade that's being spawned with local client authority. No scene changes.

    I didn't know about the syncvar one when clients connect either. Thanks for the tip!
     
  6. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I haven't experienced RPC's not working during initialization, but that's not something I do. I believe ClientRPC's are only sent to "observed" clients of the NetworkIdentity.observer. So if your ClientRPC is not working during initialization I'd speculate that somehow the client is not an observer yet (hasn't been fully initialized/spawned) and therefore it fails to deliver the ClientRPC to the client.

    Just to confirm you are calling the ClientRPC on the Server and it's failing to be received on the Client, correct?

    I will say that QA has been pretty good about replicating bugs. Once the UNET HLAPI staff gets going hopefully they will start knocking some of these bugs out. So it might be best to small bare-bones sample project that replicates the issue and bug report it.