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"

RPC from client to server not working

So I have some actor spawned from the PlayerController, let's call that actor "CheatActor", and I would like to fire client RPCs to server, and it's not working.

From the RPC Doc, it says that

  1. The Actor must be replicated

2.If the RPC is being called from client to be executed on the server, the client must own the Actor that the RPC is being called on.

I wrote the following code, they should satisfy those requirements:

 ACheatActor::ACheatActor()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = false;
     bReplicates = true;
     bAlwaysRelevant = true;
 }

And, the Cheat Actor is spawned in the PlayerController, which sets the Cheat Actor's owner to the PlayerController

 void APlayerController::BeginPlay()
 {
     Super::BeginPlay();
 
     CheatActor = GetWorld()->SpawnActor<AElekCheatActor>(AElekCheatActor::StaticClass(), FTransform());
     CheatActor->SetOwner(this);
 }

Are these enough to setup RPC from a PlayerController spawned actor for client to server RPC? Why is the RPC still not working?

Product Version: UE 4.14
Tags:
more ▼

asked Mar 25 '17 at 01:41 AM in C++ Programming

avatar image

Mantracker
102 4 11 14

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

1、Add a RPC to the playercontroller, for example, RPC_SpawnCheatActor(run on server, WithValidation) .

2、Call RPC_SpawnCheatActor in BeginPlay or other place.(Remember only call it on the client if you want to create the actor according to client input)

more ▼

answered Mar 25 '17 at 02:21 AM

avatar image

haisong
132 9 11 15

avatar image Mantracker Mar 25 '17 at 02:54 AM

When you say add an RPC_SpawnCheatActor, do you mean an RPC from client to server? or server to client?

Is the RPC not working because the actor is spawned only on the client, but not on the server?

avatar image haisong Mar 25 '17 at 04:06 AM

From client to server.

I think your problem is that your actor spawns both on client and server, but they are not the same one.You should spawn the actor on the server, and then the server replicate the actor to the client.

(comments are locked)
10|2000 characters needed characters left
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