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"

GetTimerRemaining returns -1

Hi, I cannot for the life of me figure out why this is not working.

.h

     UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Stacking")
     FTimerHandle LifeHandle; 

I have a timer in my begin play function.

 void UDts_DamageEffect::BeginPlay()
 {
     Super::BeginPlay();
 
     GetWorld()->GetTimerManager().SetTimer(LifeHandle, this, &UDts_DamageEffect::LifeExpired, fLifeOfEffect, false);
 }

and just for testing I am trying to print the time remaining

 void UDts_DamageEffect::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     
     GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Yellow, FString::SanitizeFloat(FTimerManager().GetTimerRemaining(LifeHandle)));
     
 }

I keep getting a print of -1 which means the timer doesn't exist. Am I misunderstanding the point of that function? In blueprint I can pull off the handle and use the "GetTimerRemainingTimeByHandle" function, and print the return value and get the time remaining on the timer.

Can anyone help point me to why I am not able to print the actual time remaining out of C++?

Thanks Russ

Product Version: Not Selected
Tags:
more ▼

asked Oct 24 '18 at 02:04 PM in C++ Programming

avatar image

Rstenberg
25 3 6 8

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

1 answer: sort voted first

You are creating an empty instance of a timer manager and checking for the remaining time (which is not tracking your timer)

Instead, use the same timer manager that you got from the world when you created it

Change this from:

 FTimerManager().GetTimerRemaining(LifeHandle));

to this:

 GetWorld()->GetTimerManager().GetTimerRemaining(LifeHandle));


more ▼

answered Oct 25 '18 at 11:17 AM

avatar image

Ali Akbar
691 2 6 8

avatar image Rstenberg Oct 25 '18 at 11:59 AM

Thank you! I missed an easy one there.

(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