skip to Main Content

Consuming Timelines using C++

In this tutorial I’m going to show you how you can consume and handle timelines using C++. With Timelines you can create simple time-based animations such as opening doors, altering lights or performing other time-centric manipulations to Actors within a scene. Each timeline needs at least one curve in order to run. The curve describes the transition of a value (or values – depending on the curve you provide) according to time. In this post I’m going to create a simple float curve. A float curve contains float values which interpolate between a given time range. Unreal Engine 4 provides three types of curves:

  1. CurveFloat
  2. CurveLinearColor and
  3. CurveVector

Once you get the hang of the workflow, you will be able to extend the functionality of curvefloat to the other two curves as well!

Before we get started, here is the end result of this post:

Preparing our project

In order to consume a curvefloat we need the following things:

  1. A curvefloat
  2. A timeline which contains the curvefloat
  3. A function which handles the progress of the timeline (in this post, I will create this function inside the Actor I’m going to create in a bit)

Creating a Float curve

Before we type any code, we should create our curve first. Right click somewhere in the empty space of your content browser and select the Float Curve from the Miscellaneous menu as seen below:

floatcurve_option

When you’re done with that, create the following curve (to add points in your curve hold “Shift” and click somewhere in the curve space):

floatcurve

The X axis represents the time and the Y axis represents the values that our function will take as parameters. Once you’re done, save your curve.

Creating a floating Actor

Add a new C++ class which inherits from the Actor class and name it FloatingActor. Once your header file loads, type in the following code:

Switch to your source file, and type in the following code:

Build your code and create a Blueprint based on the Actor class we created. Place it on your level and copy the following values*:

bp_options

That’s it! If you simulate your level you should have a result similar to the video in the beginning of the post!

*In case you can’t find the cone static mesh make sure to enable the following option:

engine_content

 

 

Avatar photo

This Post Has 15 Comments

  1. Hello! I have been trying to get this work but unsuccessfull. Unreal Engine doesn’t recognize the FTimeline class correctly. If i write FTimeline Mytimeline;

    Unreal engine starts to say “Unknown identifier”. Game doesn’t compile and i don’t have access to any methods of the Mytimeline. I try to update 4.13 version to date and even tried with 4.14 version. Same thing happen. Could you look up to it?

    Thanks!

    1. Hello, I think that from 4.12 version and later on you have to include the TimelineComponent.h in your header files.

      -Orfeas

  2. Great tutorial again Orfeas.

    I have one question. How would I modify this if I wanted to be able to attach the floating functionality to another existing actor?
    Would I make this into an interface class then use multiple inheritance and overrides in my other class?

    Also Line 24 of the c++ file was a little confusing but I think I understood it.

    1. Hey Max,

      You can embed that functionality in a component and then attach the component in the desired actor. By line 24 I’m assuming you’re refering to ProgressFunction.BindUFunction(this, FName(“HandleProgress”)). This line tells the compiler that when the ProgressFunction executes, it will call the HandleProgress function.

      -Orfeas

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top