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)