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

Hey,

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

    UFUNCTION(Client)
	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?

Thanks.

Look at this table:

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

Hi, I look at shooter demo, and they have

UFUNCTION(Reliable,Client)
void Foo();

void ClassName::Foo_Implementation();

In the link you sent

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

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.

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.
}

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

Cheers, great help :smiley:

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

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