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"

Server RPC is being called by client, but also run on the client?

I am trying to have the client ask the server to update a variable so that it will be replicated. Currently the variable is being replicated correctly to all clients when run by a listen server. When I am performing the action that would cause the update as a client, I successfully call a server RPC. However, if I update the variable inside the server RPC (called by the client) it is not replicated. Additionally, if I query the role inside of the server RPC, it tells me that it is the client! How can I get this to run on the server, so that the variable will be properly replicated?

Here is my server function declaration:

UFUNCTION(Reliable, Server, WithValidation) void ServerUpdateVar();

void ServerUpdateVar_Implementation();

bool ServerUpdateVar_Validate();


void ARandomActor::ServerUpdateVar_Implementation() {

 if (GetNetMode() == NM_Client)
 {
     UE_LOG(TempLog, Warning, TEXT("--------------- THE CLIENT HAS INFILTRATED THE SERVER"));
 }
 else if (GetNetMode() == NM_ListenServer)
 {
     UE_LOG(TempLog, Warning, TEXT("--------------- I AM THE SERVER"));
 }

 RandomVar++; // replicated variable

}

bool ARandomActor::ServerUpdateVar_Validate() { return true; }

Product Version: UE 4.10
Tags:
more ▼

asked Mar 03 '16 at 09:35 PM in C++ Programming

avatar image

Meagatron
81 6 13 16

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

1 answer: sort voted first

Solved this! It turns out the problem was that the client was spawning ARandomActor, and it should have been spawned by the server and then assigned ownership to the client controller. Both of those steps are necessary to make a server RPC work properly from a client actor.

more ▼

answered Mar 04 '16 at 02:50 PM

avatar image

Meagatron
81 6 13 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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