Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RPC's not being invoked

Discussion in 'Multiplayer' started by TwoTen, Jun 30, 2017.

  1. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Hello!
    I've heard multiple people talking about RPC's not being invoked. I had not experianced it before until now.
    I have a Command that's properly being invoked every time called. Works as expected. However, in there I am trying to call a RPC. And most of the time it's not being invoked at all. I tried simply putting a debug statment in there. And sometimes it works once everytime I restart the game.

    Is there a way to fix it? Causing me alot of issues. I've tried renaming the Rpc.
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    RPC's are only sent to observed clients (NetworkIdentity.observers). When I've had RPC's fail to send it was because the clients were not on the observer list briefly due to a scene change (observers are dropped and re-added 10+ frames later so there is a window where RPC's do not work during a scene change).

    I suppose it could happen during initialization too. If RPC's are called immediately before all the observers are set up then it might fail (but I haven't seen this myself).

    So take a look at the NetworkIdentity.observers and see if this is the cause.
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    1. I am not Changing scene
    2. On the observers list it just says :0.
    3. They fail all the time. Not only during initilization.

    Is there a way to remove the observer system? I don't use that anyways as I would much prefer to use TargetRpc then.
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    The observer system is core to the HLAPI. Almost everything is built on it. All SyncVars and RPC's are only sent to NetworkIdentity.observers.

    I am not sure if TargetRPC requires the client to be observing, but you can try that as a bandaid. But if the client is not observing the object there is a major underlying initialization/spawn issue. RPC is not working is just a symptom.
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    All other RPC's in that script works except that one. It's super wierd.
     
  6. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    Hmm. 2 more questions then.
    1: Is the RPC method name unique? If the name isn't unique (i.e. another script on the same object with the same RPC method name) then it the RPC can get sent to the wrong script
    2: What data is being passed by the RPC? Is it empty Method( ) or is there some data?
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    It is unique. And I tried different names.
    And I at first tried to pass a Vector3 array. Then I tried passing nothing.
    And all other RPC's works on the script. Almost like there is some RPC limit per script?
     
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Vector3, not vector3 array sorry
     
  9. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I'm almost out of ideas... not sure what's wrong.

    Any chance you are adding the NetworkBehaviour script at runtime or is it always there?
     
  10. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Allways there. I'll try to make a video shortly.
     
  11. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168

    That's the results.
     
  12. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    To add to the video. It's not neccecarly the first two Command calls when running as host. Basically If I spam the Cmd_Shoot method right when the server starts. It actually calls the RPC for all of them. But then after a second or two it stops registering it fully.
     
  13. Deleted User

    Deleted User

    Guest

    Have you tried to assign the channel of RPC? Something like reliable, [ClientRpc(channel=1)]
    where 1 - the number in your NetworkManager.
     
  14. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Same thing. I set it to Reliable Sequenced and still the same problem. The RPC works the first few seconds then no more.
     
  15. Deleted User

    Deleted User

    Guest

    Well, strange, I've never had that kind of problem before, but I would suggest that the network behavior on Editor is different from Standalone build. Did you tried something like this on an empty project?
     
  16. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Well the thing is:
    As seen in the video. On standalone Server it all works. The RPC get's invoked.
    It's only a problem when I am the local HOST (Server and Client). Meaning we MUST have the same code.
     
  17. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Could it have something to do with the fact that the Object the RPC is sitting on gets spawned in right at the start with SpawnWithClientAuthority?
     
  18. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Solved, I was disconnecting the Client due to auth failure. And thus the client was disconnected but since I was host I did not actually notice that it was disconnected.
     
    Deleted User likes this.