x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Client RPC gets called sometimes on the Client

Greetings, Hope everyone is doing good today.

I'm having a small issue perhaps someone can point me in the right direction. Its relevant to network replication. I have a RunOnClient that gets called sometimes, and sometimes doesn't. What I mean is that there is a function marked as (Client, Reliable) on the PlayerController that is always called on the server side, but on the Client side, it gets called when it feels like it lol.

The framework is the following.

Server receives input from the client, verifies values.

Once the information has been Confirmed,

1) Call GameMode function that calls a GameState function

2) Runs logic, then it calls a Client function inside the PlayerController.

Breakpoints indicate, both the reference to the PlayerController is correct and the Function is in fact getting called... it's just that sometimes the Client never calls it on his end.

Any tip is more than welcome!

As always Happy Dev'n!

UPDATE ----------------------------------------------

So I toggled between Reliable and Unreliable and had some interesting results.

  • Reliable : Whenever the function is not called on the Client side, I have to close down the Dedicated server and re-open it to try again, otherwise if I keep trying the input without closing the Dedicated server, it'll keep calling the "Client" function but it'll never be received on the Clients end.

  • Unreliable : When the function is not called on the Client side, I can just enter the input again and it does called not always on the second try, but surely in the next couple of tries without the need to close and re-open the Client or the Dedicated Server.

Product Version: UE 4.21
Tags:
more ▼

asked May 27 '19 at 05:01 PM in C++ Programming

avatar image

Luis_Martinez
90 7 10 21

avatar image ArcainOne May 28 '19 at 05:07 AM

That is very weird indeed, The only time I've seen behavior like this is when something is not marked to be replicated (usually in the case of a component or subobject) or you are calling the "wrong" function, such as the case of an interface function with the same name as a function on your object.

In such cases I run the debugger in "GameDebug Editor" (so that operations do not get optimized away or occur in a funky order) and use the following:

 #if WITH_EDITOR
 ENetMode netMode = GetWorld()->GetNetMode();
 ENetRole netRole = Role;
 #endif

This code will only exist when your game is built with the editor and while debugging you can verify you are in the right world (Client, Server, etc) and what role the current actor has. Just throw a break point right there and when the code get's executed it will halt execution and you can see the values by hovering over them in VS. Of course this is assuming your code is done in C++ haha.

avatar image Luis_Martinez May 28 '19 at 05:00 PM

Yes it is done through C++. I don't really understand very well why it keeps calling the function on the server side with all of the correct values, but the breakpoints inside the Client function in the Playercontroller gets called sometimes...

Maybe I should explain a bit better how its manages.

I have a UDPComponent, that is created in the constructor of a UDPActor, which is Spawned through the Begin Play of the Level Actor with a (HasAuthority) to confirm we spawn as a Server.

So , Client inputs name -> Tells UDP to send data to Other Dedicated server, -> Once received, it verifies some logic and returns the answer, indicating if he in fact can choose that name -> Calls UDP to send the info back to requesting Dedicated Server -> Dedicated server calls GameMode Func -> Calls GameState Func to confirm the requesting Client -> Tells Client to call Run on Client function located in the player controller..

I don't see what I'm missing.. and what is annoying is that it works sometimes... Should I have bReplicates on both the UDP Actor and UDP Component?... or where should I be looking for the error... again, the UDP communication is working fine since I am receiving the information and the values are all correct.

avatar image ArcainOne Jun 07 '19 at 09:03 PM

First of all, what you are doing sounds fascinating! Would love to see that code haha. So what it sounds like you are doing is communication between two dedicated servers and a client on one of them. Could it be possible that some times the function call is happening on the wrong dedicated server? Generally a component only needs to replicate if it needs to have values on the client (and I assume another server) and also to fire RPC calls. If your Actor is doing all the replicating and RPCs than the Component does not need to replicate.

avatar image Luis_Martinez Jun 08 '19 at 04:07 PM

Nah, it is being called on the correct Server. I have a on going server that manages the Matchmaking process, and is in charge of creating other dedicated servers to gather small groups in. Both of those server have different maps and different GameModes. I debug with breakpoints and the correct GameMode is being called once the small dedicated server is receiving the info back from the Matchmaking Server.

The only reason why I would see a Run On Client not being called is if the actor who is calling it is :

  • Not an Actor Class

  • That Actor is not replicated

  • The client doesn't own that actor

So it doesn't make sense.. the Client RPC is a function created inside the PlayerController and that checks all of the boxes.. its an Actor Class, Replicated and Owned by the Client. I even made sure that the value of the playercontroller reference is correct, and it is.

avatar image Luis_Martinez Jun 14 '19 at 04:50 AM

UPDATE ----------------------------------------------

I just noticed that if I run the on going server and Attach its process to C++ debugger... the code ALWAYS works. But once I detach it from the debugger, it goes back to not working.. I don't think I have ever had such issue.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question