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"

How do I perform a Run On Owning Client in c++


In my Game project.h I have

 #include "Engine.h"
 #include "Net/UnrealNetwork.h"

So I let the client and server simulate physics, but at the end of the frame, I want the server to correct the client, (Since Pawn isn't network enabled).

in MyPawn.h

     void ClientSmoothTransform(FVector location, FRotator rotation);

In my Tick function

     if (Role > ROLE_Authority)
         ClientSmoothTransform(PhysicsBoxPrimitive->GetComponentLocation(), PhysicsBoxPrimitive->GetComponentRotation());

In my MyPawn.CPP

 void AMyPawn::ClientSmoothTransform(FVector location, FRotator rotation)
     //the server will give the owning client the severs pawn location and rotation
     PhysicsBoxPrimitive->SetWorldLocationAndRotation(location, rotation);

I checked the RPC on the UE4 web page, but they do not show how to implement CLIENT RPC calls.

Just to be clear

UFUNCTION(Client) means - run on the owning client ? So the client who owns the Pawn on the Server?


Product Version: UE 4.9
more ▼

asked Mar 24 '16 at 11:54 PM in C++ Programming

avatar image

219 19 17 24

avatar image BrUnO XaVIeR Mar 25 '16 at 12:19 AM

Look at this table: https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Actors/RPCs/index.html#rpcinvokedfromtheserver

The results of RPC calls depends on net ownership of the pawn. RPCs need _Implementation attached to their name on the .CPP function body.

avatar image Moynzy Mar 25 '16 at 12:46 AM

Hi, I look at shooter demo, and they have

 void Foo();
 void ClassName::Foo_Implementation();

In the link you sent

 UFUNCTION( Client, Reliable );
 void ClientRPCFunction();

avatar image BrUnO XaVIeR Mar 25 '16 at 12:59 AM

Yes, in that page they do not show the function body. It's just

 void class::FunctionName_Implementation() {
     // If (Client) this will run on owning client, but called by server.

avatar image Moynzy Mar 25 '16 at 01:07 AM

So I will use the below in .h

     UFUNCTION(reliable, client)
     void foo();

and this in CPP

     void Classname::foo_Implementation() {//code;}

and clients can't call this, only the server can call this.

So from Game Mode class, I will get all player controllers, and call this function.

avatar image BrUnO XaVIeR Mar 26 '16 at 07:51 PM

Yes, then from Controller you can call a local function that updates the physics body on the client.

avatar image Moynzy Mar 28 '16 at 11:12 PM

Cheers, great help :D

avatar image Moynzy Mar 28 '16 at 11:13 PM

@BrUnOXaVIeR why from controller, and not the APawn class it self?

avatar image BrUnO XaVIeR Mar 29 '16 at 01:54 AM

No reason really, you can do it on Pawn/Component/etc as well.

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

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