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:
- CurveLinearColor and
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:
- A curvefloat
- A timeline which contains the curvefloat
- 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:
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):
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*:
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: