Move actor along spline / path (UE4 & UE5)

This tuto­r­i­al will teach you how to move actor along spline in Unre­al Engine.

In this step-by-step how-to guide, you will learn how to move actor along spline or move object along spline in Unre­al Engine.

1. Cre­ate an actor with the Spline component

First, we’ll need our actor with the spline — the actu­al path our char­ac­ter will fol­low. Cre­ate a new blue­print of the Actor type and call it BP_Path. Add the Spline com­po­nent and save. That’s it, no need to do any­thing else with this actor. You’ll end up with a straight­for­ward hierarchy:

2. Cre­ate the actor that you’re going to move along the spline

If you don’t already have the object you want to move, cre­ate one. Mine’s called BP_Courier. Add a sta­t­ic or a skele­tal mesh com­po­nent to it so that it’s vis­i­ble in the game world, and don’t for­get to set this com­po­nent up with an actu­al object. 

3. Cre­ate three variables

Cre­ate three new vari­ables in your BP_Courier:

  • Alpha of type float — it’s going to be used in the updat­ing of our actor’s loca­tion and rotation.
  • Duration of type float — with this, you’ll set up the actu­al length of the movement.
  • Path Ref of type BP_Path (Object ref­er­ence) — this is a ref­er­ence to the path actor we’ve cre­at­ed in step 1. Make it public.

4. Cre­ate a timeline

Right-click in the blue­print graph and type in “time­line,” then select Add Time­line action. You can call it what­ev­er you like; I’ve called it Move.

Dou­ble-click the time­line to open it for edit­ing. Next, cre­ate a new float track by click­ing the but­ton with the f+ sym­bol. Call it Alpha.

Add two keyframes by click­ing Shift + Left Click in the float track. Select the first one and set both the Time and the Val­ue to 0,0. The sec­ond one should have Time and Val­ue set to 1,0 and 1,0 accordingly.

Final­ly, set the Length of the time­line to be 1.00. Basi­cal­ly, you want to make your float track go from 0 to 1 in the span of 1 sec­ond lin­ear­ly. You should end up with this:

5. Set up the actor’s loca­tion and rota­tion to be updat­ed with the timeline

Use the SetAc­tor­Loca­tio­nAn­dRo­ta­tion node to update our actor’s loca­tion and for our alpha to be stored in a variable:

The code that helps us move actor along spline

As you can see, I’ve col­lapsed the nodes that pro­vide the actu­al rota­tion and loca­tion into a sin­gle node. So here’s how it looks on the inside:

Click the image to view at full size

6. Hook up the duration

Now let’s uti­lize our Dura­tion vari­able. I’ve cre­at­ed a cus­tom event called MoveThe­Dum­my to final­ize the whole move­ment into a sin­gle event. Here we first set the play rate of the time­line and then start it:

The Move Time­line node on the right is the same one we’ve cre­at­ed before

All you need to do here is to set up the default val­ue for the Dura­tion in sec­onds.

After this, you can call the MoveThe­Dum­my event how­ev­er you like — I’ve plugged it into the Begin­Play event. We’re now fin­ished with the script­ing. Let’s go set up our scene.

7. Add actors to the scene and cre­ate the Spline path

Final­ly, to move our object along the path, you need to drag your BP_Courier (or what­ev­er you’ve called it) and BP_Path into the scene. Then, click the BP_Path to cre­ate the actu­al path your character/object is going to follow. 

You can either check the offi­cial doc­u­men­ta­tion on this or use a time-sav­ing life­hack of right-click­ing pre­cise­ly into the spline point and select­ing Spline Gen­er­a­tion Pan­el from the menu. This will open a handy tool that will allow you to quick­ly cre­ate a spline path in the form of a cer­tain shape.

Select your BP_Courier and fill our pub­lic Path Ref vari­able with the BP_Path from our scene in the Details pan­el. That’s it!