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 create a Timeline in C++?

Hi,

i'm trying to set up a timeline in c++.

.h:

 FTimeline TimeLine;
 UFUNCTION()
     void EffectProgress(float Value);

.cpp:

Constructor:

     const ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("CurveFloat'/Game/OwnStuff/EffectCurve.EffectCurve'"));
     TimeLine = FTimeline{};
     FOnTimelineFloat progressFunction{};
     progressFunction.BindUFunction(this, "EffectProgress");
     TimeLine.AddInterpFloat(Curve.Object, progressFunction, FName{TEXT("EFFECTFADE")});

BeginPlay:

     TimeLine.PlayFromStart();

The function which should get called from the timeline:

     void AEffectBallSpeed::EffectProgress(float Value)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("EFFECT PROGRESS"));
     }


The function is called once. How can it be triggered all the time? thx :)

edit: changed the name of the question to make it more clear and easier to find for others.

Product Version: Not Selected
Tags:
more ▼

asked Oct 13 '14 at 08:29 PM in C++ Programming

oOo.DanBO.oOo gravatar image

oOo.DanBO.oOo
372 19 27 404

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

This is my actual solution

Effect.h:

 /************************************************************************/
 /* TIMELINE                                                             */
 /************************************************************************/
 /** Timeline for the effectprogress*/
 FTimeline TimeLine;

 /** Deltatime(stepsize) for the timer calling the timeline tick */
 static const float DELTATIME;

 /** Function which gets called from the Timer to call EffectProgress */
 void TickTimeline();

 /** Function which gets called from the Timeline on a Tick */
 UFUNCTION()
 void EffectProgress(float Value);

Effect.cpp:

  • Constructor:

     const ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("CurveFloat'/Game/OwnStuff/EffectCurve.EffectCurve'"));
     TimeLine = FTimeline{};
     FOnTimelineFloat progressFunction{};
     progressFunction.BindUFunction(this, "EffectProgress"); // The function EffectProgress gets called
     TimeLine.AddInterpFloat(Curve.Object, progressFunction, FName{TEXT("EFFECTFADE")});

  • BeginPlay:

     TimeLine.PlayFromStart();
     FTimerHandle TimerHandle;
     GetWorldTimerManager().SetTimer(TimerHandle, this, &AEffectBallSpeed::TickTimeline, DELTATIME, true, 0.0f);

  • Called Function from Timeline

 /** The function which gets called from the timeline tick */
 void AEffectBallSpeed::EffectProgress(float Value)
 {
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("EffectProgress: timeline: %f  value:%f"), TimeLine.GetPlaybackPosition(), Value));
     // do something
 }

  • Called Function from Timer

 /** Function which gets called from the Timer to call EffectProgress */
 void AEffectBallSpeed::TickTimeline()
 {
     if (TimeLine.IsPlaying())
     {
         TimeLine.TickTimeline(DELTATIME);
     }
     else
     {
         GetWorldTimerManager().ClearTimer(this, &AEffectBallSpeed::TickTimeline);
         SetLifeSpan(0);
     }
 }
more ▼

answered Oct 14 '14 at 09:21 PM

oOo.DanBO.oOo gravatar image

oOo.DanBO.oOo
372 19 27 404

spaceharry gravatar image spaceharry Apr 05 '16 at 09:57 PM

This is still Nr1 on Google for c++ timelines and this answer is a bit misleading for using tick of the actor for the timeline. The timeline component itself has already a tick which can be used for this I think. I wrote an answer with a code example here:

https://answers.unrealengine.com/questions/384597/link-to-timelines-doc-for-c.html#answer-400083

Azarus gravatar image Azarus Dec 10 '16 at 08:40 PM

And what if you want to use a timeline in an actor component? If i want to use a timeline on an actor then i would use your code :)

(comments are locked)
10|2000 characters needed characters left

Hi,

I'm trying to transcribe this script for a BPFunction.... I Receive error when trying access GetWorldTimerManager() from UBlueprintFunctionLibrary and not found....

I Necessary Create This to Modify parameters why Dynamic Curves Floats... various equals curves in Diff Seconds..

How I Change this line to found method??

 GetWorldTimerManager().SetTimer(TimerHandle, xSpotLight, &UVJWorkspace::TickTimeline, DELTATIME, true, 0.0f);

alt text

bug.png (50.4 kB)
more ▼

answered May 08 '15 at 01:53 AM

CrashAngel gravatar image

CrashAngel
71 4 10 17

Doug Wilson gravatar image Doug Wilson ♦♦ STAFF May 08 '15 at 01:20 PM

Hey CrashAngel-

GetWorldTimerManager is a function defined in the Actor class. Including Actor.h in the source file that accesses GetWorldTimerManager should allow it to be recognized.

Cheers

Doug Wilson

(comments are locked)
10|2000 characters needed characters left

Hey oOo.DanBO.oOo-

Timelines only run once for each time they are called. With the timeline being called within BeginPlay, that means that it will only trigger at the start of the level that is being loaded. You would have to call it from another event that can be re-triggered if you want the timeline to repeat.

Cheers

Doug Wilson

more ▼

answered Oct 13 '14 at 09:27 PM

Doug Wilson gravatar image

Doug Wilson ♦♦ STAFF
49.2k 766 23 537

oOo.DanBO.oOo gravatar image oOo.DanBO.oOo Oct 14 '14 at 05:58 AM

Hi Doug, Yes the timeline runs once. But what i want it that as long as the timeline is running, it should call some function or set some value. I would expect, that EffectProgress gets called each tick, as long as the timeline is running and this doesn't happen.

danielvmacedo gravatar image danielvmacedo Oct 14 '14 at 12:55 PM

Thats exactly what I want to know too =)

Doug Wilson gravatar image Doug Wilson ♦♦ STAFF Oct 14 '14 at 03:15 PM

A timeline is used to spread out an event over the length of the timeline (think a drawbridge going up) rather than continuously preforming that event while the timeline is playing. To get the behavior you're looking for, however, it may be possible to set a boolian to true at the start of the timeline (and reset to false at the end), then use the event Tick to check the boolian and call your EffectProgress method.

oOo.DanBO.oOo gravatar image oOo.DanBO.oOo Oct 14 '14 at 09:25 PM

Hi Doug, thanks very much :) you brought me on the right track :) i got it all working now. TimeLine.IsPlaying() is also fine for me to check if im at the end of the Timeline.

Thx for the help :)

(comments are locked)
10|2000 characters needed characters left
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