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?

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)

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?

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.