I have some updating issue for a widget.
Replication comes slower than updating.
Use() function should work on the server side only.
void ADreampaxCharacter::Use()
{
// Only allow on server. If called on client push this request to the server
if (Role == ROLE_Authority)
{
ADreampaxUsableActor* Usable = GetUsableInView();
if (Usable)
{
Usable->OnUsed(this);
// Update Inventory Widget
ClientUpdateInventoryWidget();
}
}
else
{
ServerUse();
}
}
void ADreampaxCharacter::ServerUse_Implementation()
{
Use();
}
ClientUpdateInventoryWidget() function is used for updating an inventory widget.
// Update Inventory Widget
void ADreampaxCharacter::UpdateInventoryWidget()
{
ADreampaxPlayerController* PC = Cast<ADreampaxPlayerController>(Controller);
if (PC)
{
PC->ClientHUDUpdateInventoryWidget();
if (Role == ROLE_Authority) UE_LOG(LogTemp, Warning, TEXT("!!! Slot updated on SERVER !!!"));
if (Role < ROLE_Authority) UE_LOG(LogTemp, Warning, TEXT("!!! Slot updated on CLIENT !!!"));
}
}
void ADreampaxCharacter::ClientUpdateInventoryWidget_Implementation()
{
UpdateInventoryWidget();
}
And the same logic chain in the controller cpp
void ADreampaxPlayerController::ClientHUDUpdateInventoryWidget_Implementation()
{
ADreampaxHUD* HUD = Cast<ADreampaxHUD>(GetHUD());
if (HUD)
{
HUD->UpdateInventoryWidget();
}
}
“Use” function adds an item to the inventory on the server side. Inventory is a container with replication (another cpp file).
Unfortunately updating of widget on the client side comes faster than replication of Inventory from server to client.
How the updating function can be sure that the replication in the Inventory container is finished.
Time delay is not an answer.
Every tick updating is not stylish.
Thanks in advance!