RPC Client To Server Doesnt work [Only C++]

Hi. I am in a project where I call from my character a function (event) which on the server calls another function which is responsible for passing data to all connected clients. At this moment only prints in each of the clients an on-screen text.
The problem is that instead of calling it on all clients it only calls it on the server and does not pass it on to the others.

This only happens in C ++
In “Blueprints” everything works fine.

Help me please.

PlayerBase.h Code:

UFUNCTION(BlueprintCallable, Category = "Actions", Server, Reliable, WithValidation, meta = (DisplayName = "Action Server", ToolTip = "Action function to the server. \n  this function is a part of multiplayer system"))
		void ActionServer(AItemBase* Item);

PlayerBase.cpp Code:

bool APlayerBase::ActionServer_Validate(AItemBase* Item)
{
	//Usamos esto para ver si el cliente esta utilizando trucos:(WIP)
	return true;
}

void APlayerBase::ActionServer_Implementation(AItemBase* Item)
{
	if (!IsValid(Item))
		return;

	if (isDebugMode)
		print("Action Server Called!");

	switch (Item->Type)
	{
		default:
			if (isDebugMode)
				print("Item Type None!");
		break;

		case EItemType::ITEM_GUN:
			if (isDebugMode)
				print("Item Type Gun!");
			Item->OnPickUp();
		break;
	}
}

ItemBase.h Code:

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Gun Properties")
		AGunBase* GetGunData();

	UFUNCTION(BlueprintCallable, Category = "Actions", Reliable, NetMulticast)
		void OnPickUp();

	UFUNCTION(BlueprintCallable, Category = "Actions", Reliable, NetMulticast)
		void OnDrop();

	UFUNCTION(BlueprintCallable, Category = "Actions", Reliable, Server, WithValidation)
		void OnSpawn();

ItemBase.cpp Code:

void AItemBase::OnPickUp_Implementation()
{
	if (Collision->IsSimulatingPhysics())
		Collision->SetSimulatePhysics(false);

	switch (Type)
	{
		default:
		break;

		case EItemType::ITEM_GUN:
			if (!GetGunData()->IsValidLowLevelFast())
				break;

			if (isDebugMode)
				GEngine->AddOnScreenDebugMessage(-1, 3, FColor::Red, "Gun Type Multicast");

			GetGunData()->Reciver->SetSimulatePhysics(false);
			GetGunData()->Reciver->SetAllBodiesSimulatePhysics(false);
			GetGunData()->Reciver->SetVisibility(false, true);
		break;
	}
}

void AItemBase::OnDrop_Implementation()
{
	switch (Type)
	{
	default:
		break;

	case EItemType::ITEM_GUN:
		if (!GetGunData()->IsValidLowLevelFast())
			break;

		SetActorLocation(GetGunData()->Reciver->GetComponentLocation());

		AttachToActor(
			GetGunData(),
			FAttachmentTransformRules(EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, true),
			NAME_None
		);

		GetGunData()->Reciver->DetachFromComponent(FDetachmentTransformRules(EDetachmentRule::KeepWorld, true));
		GetGunData()->Reciver->SetSimulatePhysics(true);
		GetGunData()->Reciver->SetAllBodiesSimulatePhysics(true);
		GetGunData()->Reciver->SetVisibility(true, true);
	
	break;
	}
}

Blueprint Created Events: (this works fine)

any ideas?

Hi. Have you enabled replication for your player in c++ version?
Try to call SetReplicates(true); for your PlayerBase (in constructor). I’ve tried to create similar system, but based on custom components - it works fine but only when replication is enabled.

thank you very much. But still not working

Well, this is very similar to the previous answer, but the behavior you describe is exactly what I would expect to see if you don’t call SetReplicates in the constructor of ItemBase (or if the items don’t get replicated for some other reason). Can you add some debug messages to your code to verify that the items are actually spawned on the clients?

OK, one thing that just stood out in your code: you are attaching and detaching the actor to/from other actors. Are the actors to which you attach the BaseItem when it is not attached to the pawn net relevant? Because if they are not, then this is what causes the RPC to not propagate.

SetReplicates (true) is called in the ItemBase and PlayerBase constructor but does not work.
I will try to debug the clients if the item is replicating correctly. But clients can currently view the items. So it seems that if they are replicating.

It is like the function ignores that it has the parameters in: “NetMulticast”

All actors are replicated in the network. The server is responsible for creating an item and from there is replicated to all clients (that works well) but when one of these items I want to put invisible only happens on the server.

Yes, but even if the actor is replicated initially, once you change its owner it might no longer be net relevant and therefore not receive RPCs. I would try to set bAlwaysRelevant on ItemBase objects to see whether this is what prevents the RPS from being executed.

bAlwaysRelevant is active in the itembase i put it in constructor

OK, trying to think of other possibilities why this might fail: Is the Type property replicated properly? If it is not and you set its value on the server you might hit the default case in your switch statement and never execute the code for guns.

The variable is not replicated. I’m going to prove what you mentioned!

The variable is replicated and working. But items do not disappear in the client only happens on the server.

0] is None or Default
1] is Gun

Images of Debug: Replicated Variable is Type (Red Text)
(In the client does not appear the text only by the time that takes in taking the screen capture.)
This screen is captured from RPC from client to server.
Server:

Client:

The solution is simply replicating in network the variable that contains the weapon. In this case “ItemGun” so that all clients are updated the object / item

PS: The code has to look like mine.
Code:

UPROPERTY(Replicated)
		AGunBase* ItemGun;