x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to call C++ function after replication is finished

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!

Product Version: UE 4.17
Tags:
more ▼

asked Sep 20 '17 at 02:56 AM in C++ Programming

avatar image

SvarogZ
49 10 12 21

avatar image SvarogZ Oct 05 '17 at 06:27 AM

still looking for answer.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The answer is very very simple

h

 UPROPERTY(Transient, ReplicatedUsing = OnRep_VariableIsReplicated)
 bool MyAnyVariableForReplication;
 
 UFUNCTION()
 void OnRep_VariableIsReplicated();

cpp

 void ADreampaxPickupActor::OnRep_VariableIsReplicated()
 {
     // This function starts in case of replication for MyAnyVariableForReplication
     // Do something
 }
 
 void AMyActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> & OutLifetimeProps) const
 {
     Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 
     DOREPLIFETIME(AMyActor, MyAnyVariableForReplication);
 }



more ▼

answered Dec 08 '17 at 09:08 AM

avatar image

SvarogZ
49 10 12 21

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question