How to feedback between server and client?

I have this replicated variariable and its notify function

	UPROPERTY(ReplicatedUsing=Rep_NotifyToClient)
	bool Success=false;

	UFUNCTION()
	void Rep_NotifyToClient();

Now i want to notify to server too… basicly server want to know when Rep_NotifyToClient() was executed.

void MyClass::Rep_NotifyToClient()
{
	if (Success)
	{
		//Feedback  to server
	}
}

Is it possible to do this? How?
Thank you so much!!


I found some info…
RPCs | Unreal Engine Documentation.

The only communication from a client to a server is from an Actor the Client already own using a Server RPC.

Can you give me a hand please?
For some reason I can’t get the GameModeBase instance.
Do you know why?

I am trying to do this (It’s based on your comment):

void MyClass::Rep_NotifyToClient()
{
	if (Success)
	{
	    UWorld* World = GetWorld();
	    AReplicationInfo *ReplicationInfo = 
        World->SpawnActor<AReplicationInfo>();
	}
}

The Actor Class:

UCLASS()
class AReplicationInfo : public AInfo
{
	GENERATED_BODY()	
public:
	AReplicationInfo(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

protected:
	virtual void BeginPlay() override;
public:
	UFUNCTION(Server,Unreliable)
	void NotifyToServer();	
};

And the implementation;

//-----------------------------------------------------
AReplicationInfo::AReplicationInfo(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{	
	//PrimaryActorTick.bCanEverTick = true;
	bReplicates = true;
	bAlwaysRelevant = true;
	NetPriority = 3.0f;
	SetReplicatingMovement(false);
}
//-----------------------------------------------------
void AReplicationInfo::BeginPlay()
{
	Super::BeginPlay();
	if (!HasAuthority()) return;
	NotifyToServer();	
}
//-----------------------------------------------------
void AReplicationInfo::NotifyToServer_Implementation()
{

	UWorld* World = GetWorld();
	if (!IsValid(World))
	{
		message::Error("World is NULL!!");
		return;
	}
	AGameModeBase* GameModeBase = 
       World->GetAuthGameMode();
	if (!IsValid(GameModeBase))
	{
		message::Error("GameModeBase is NULL!!");	
		return;	
	}
}
//-----------------------------------------------------

Thank you so much

I think the actor has spawned into the client world where GameMode doesn’t exist.

It is true that the client has authority if it uses over the actor it has created, but without an instance of GameMode there is no way to communicate with the server.

I tried to replicate a world pointer from the server and it didn’t work.

I also tried to replicate a pointer to GameMode instance and that didn’t work either.

Any ideas?

You need to ensure that Replicated Actors are only spawned on the Server so they replicate to the clients.

Replicating pointers of objects that are not replicated won’t work.

You need to give ownership to the client that you want to call the server RPC from. Clients already have ownership of possessed Pawns and their PlayerController but it is possible to SetOwner on any other replicated Actor during spawning or on an existing Actor.

I will try that. Thank you so much!!

I have this now:

LogNet: Warning: UNetDriver::ProcessRemoteFunction: No owning connection for actor ReplicationInfo_0. Function NotifyToServer will not be processed.

Executing like this:

void MyClass::Rep_NotifyToClient()
{
	if (Success)
	{
       ReplicationInfo->NotifyToServer();	
	}
}

I replicated the actor:

DOREPLIFETIME(UMyClass, ReplicationInfo);

And then Spawn into server World:

void MyClass::BeginPlay()
{
	Super::BeginPlay();
	if (!GetOwner()->HasAuthority())return;
	UWorld* World = GetWorld();
	ReplicationInfo = World->SpawnActor<AReplicationInfo>(); 
	SetReplicationInfoOwner();
}

And the set owner function:

UFUNCTION(Client, Unreliable)
void SetReplicationInfoOwner();
void MyClass::SetReplicationInfoOwner_Implementation()
{
        //Client is the Owner
	ReplicationInfo->SetOwner(GetOwner());  
}

NOTE: i used GetOwner() because MyClass is an ActorCoponent.

What did I do wrong?

You only need to call SetOwner on the Server just after you spawn the Actor. No need for the client RPC. The Actor Owner could be the Client PlayerController or Pawn or something else that the client already own.

After you have Set the owner by the server you can use the OnRep_Owner callback and when the Owner is valid you are ready to send the Server RPC from the client.

My Actor is the AGameState derived Class… the actor component is a UGameStateComponet… So, there is not controller and there is no pawn… ¿Culd be that the problem?

All connected Clients have a PlayerController.

Yes you should not give ownership of GameState to any particular player.

If you want to avoid the Ownership problem you could add a Replicated Component to the PlayerController and have the Server RPC here.

I’ll try the controller. Thank you so much!!

Just keep in mind that PlayerControllers are only replicated to the owner so you can only replicate variables to that specific Client on the PlayerController and it’s components.

i will, thank you!!

From the player controller it does work perfect!!

void MyClass::Rep_NotifyToClient()
{
	if (Success)
	{
	    APlayerController* PlayerController = 
           UGameplayStatics::
           GetPlayerController(GetWorld(),0);


	   AGamePlayPlayerController 
          *GamePlayPlayerController = 
           Cast<AGamePlayPlayerController>
          (PlayerController);


	    if (!IsValid(GamePlayPlayerController))
	    {
		   message::Error(
                  "GamePlayPlayerController is NULL");
		   return;
	   }

	     GamePlayPlayerController->
             NotifyReplicationToServer();
	}
}

I can finally know when the data is available on the client side and synchronize things from the server. Especially at the beginning of the game and when loading the map.

Thank you very much for your help.
Really Really very much appreciated. :heart: