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"

disable UnFreeze timer on PlayerController

Is there any way to temporarily disable the PlayerController's UnFreeze timer on both client and server? For example if we are going to travel to another map we don't want BeginInactiveState() to set TimerHandle_UnFreeze and later trigger UnFreeze().

Even if we try to manually clear this timer BeginInactiveState() will set it again. BeginInactiveState() is called whenever my player ServerTravels to a new map and then UnFreeze() will be called on both the client and the server after the player has loaded into the new map.

I want this functionally normally when the game is active but only want to disable in a case like when using seamless travel to reload the map.

Product Version: UE 4.18
Tags:
more ▼

asked Mar 12 '18 at 09:54 PM in C++ Programming

avatar image

jr557
48 10 12 19

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

1 answer: sort voted first

BeginInactiveState() is virtual so you can override and add bool property to switch on/off this timer.

 void AMyPlayerController::BeginInactiveState()
 {
     if ( (GetPawn() != NULL) && (GetPawn()->Controller == this) )
     {
         GetPawn()->Controller = NULL;
     }
     SetPawn(NULL);
 
     if(bUnFreezeEnabled)
     {
         GetWorldTimerManager().SetTimer(TimerHandle_UnFreeze, this, &APlayerController::UnFreeze, GetMinRespawnDelay());
     }
 
 }



more ▼

answered Mar 12 '18 at 11:17 PM

avatar image

Shaggy41
341 2 7 5

avatar image jr557 Mar 12 '18 at 11:33 PM

Thanks for the answer. The only thing is, would the bool bUnFreezeEnabled have to be replicated in order for this to work properly? Based on my testing, BeginInactiveState() is executed on both the server and client for the same PlayerController. So both the server and client version of the PlayerController would have to know about changes to this bool.

avatar image Shaggy41 Mar 13 '18 at 04:24 PM

It depends on how you want it to work.

[1] If bUnFreezeEnabled will not be replicated then the server and client can have different values in bUnFreezeEnabled

[2] If bUnFreezeEnabled will be replicated then when the server change value in bUnFreezeEnabled, the same value will be on the client side, but if the client change bUnFreezeEnabled, the change will only occur on this client. So there is still the possibility that the server and client will have different values in bUnFreezeEnabled.

[3] If bUnFreezeEnabled will be replicated and, for example, you will have a function:

 void AMyPlayerController::UnFreezeEnabled(bool Value)
 {
     if (Role == ROLE_Authority) // Only server can change bUnFreezeEnabled
     {
         bUnFreezeEnabled = Value;
     }
 }

Then only the server has the ability to modify bUnFreezeEnabled, so the value will be the same on the server and on the client.

Remember to add the replicated properties to the following function:

 void AMyPlayerController::GetLifetimeReplicatedProps( 
     TArray< FLifetimeProperty > & OutLifetimeProps 
 ) const 
 { 
     Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 
     DOREPLIFETIME_CONDITION(AMyPlayerController, bUnFreezeEnabled, COND_OwnerOnly); 
 } 

(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