Spline Component Unreal Engine 4

Make your Character to follow a Spline component Unreal Engine 4

Spline component Unreal Engine 4

As a beginner in Unreal Engine 4, many people wonder how they can make their character to follow a curved path. Then they come to know about Spline components using which they can set up a curved path easily into their level. Now they need to make their character in such a way so that it can follow this spline path or custom curved path . So in this post we will be looking into some of the basic functions of Spline component which we can use to make our character move on spline automatically.

  1. First of all, create a new project in Unreal Engine 4 and use Third Person Template Blueprints for your project. You can choose some other template too, as per your wish.



  2. Now go to “Blueprints” folder in your ThirdPersonGame and create a new Blueprint Class of type Actor. We are naming it as “SplineBP” for this tutorial.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

     

  3. Now open this Blueprint.You will find “Add Component” option to top left, after opening this blueprint. Search for a Scene component and add it. Drag this scene component over your Default Scene Component to get rid of default Sphere in viewport of your blueprint. Now click on Add Component again to find “Spline” and add it to your blueprint. Compile and save your blueprint.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

     

  4. Open your level blueprint and drag this newly created Spline BP into your level. Now select the spline point and use “ALT + drag” to add more spline points to your spline. Now you can create a predefined path in your level using this Spline BP.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

     

  5. Now in your Blueprints folder, find ThirdPersonCharacter Blueprint and open it. You will find default functionalities in this blueprint related to your character movement. We will be working in “Movement input” section of event graph to make our character move along Spline.
    We will create two variables here. First variable of type “Spline BP” which will store reference to our Spline BP. Second variable named “SplineDistance” of type float which will store the distance traversed along the Spline path.

    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4
  6. Now take the Spline BP reference in your Character Blueprint and find a node “Get World Location at Distance along Spline” and select it. Pass the SplineDistance variable that we have just created into the Distance field of the node. Similarly look for “Get World Rotation at distance along Spline”.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

     

  7. Now find nodes “Set Actor Location” and “Set Actor Rotation”. Now pass the outputs of nodes in above step to these nodes. It will set the Rotation and Location of your Character. As we want this to update constantly, we will do these changes inside tick event. Find the “Input axis move Forward ” node that was present by default in Movement Input section of your Third Person Character Blueprint. Replace this node with “Event Tick” and set the Scale value in  “Add Movement Input” node to 1.

    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4
  8. This will unable our Character to update its location and rotation continuously. But still you will find there is no movement in character, because the “Spline Distance” variable is fixed at value 0.0 and at every frame, location and rotation of starting point of Spline is being set to the character. So we need to add some value to our Spline distance every frame, which will make our character to move that particular distance every frame on our spline.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

     

  9. The final Blueprint will look something like below.

    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4
  10. Compile and Save. Still you will find error, because the Spline BP reference is having no value yet and is null. Open your Spline BP Blueprint and go to its event graph. Here in Event Begin Play method set the value of Spline BP variable which is in Third Person Character. Check Blueprint Communication in detail here.
    Spline Component Unreal Engine 4
    Spline Component Unreal Engine 4

    That’s it. Compile and Save , you are good to go now. Please let us know if you are facing any problem. We’ll be more than happy to help.

Social sharing
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on TumblrEmail this to someone

37 thoughts on “Make your Character to follow a Spline component Unreal Engine 4”

  1. Hi – I was wondering if you tried to constrain an AI Bot to a path and if so have you any screenshots or tutorial for the blueprint setup ?
    Thanks

      1. Hi thanks for doing the AI BOT tutorial. I have a question relating to step 5 above..if spline distance is a float variable what type of variable should spline bp be set as? I’m using v4.9 and the same blue colour that you have in your screenshot doesnt seem to be an option.

        1. It is reference to Object of the Blueprint , that you created in Step 2. Just search for SplineBP , and click on Spline BP Object.

          1. Hi – I have followed the tutorial and am getting three problems.
            1. The character is being placed too low on the z axis and falls through the terrain as a result. Changing the z axis of the spline makes no difference.

            2. The character appears to be running immediately (without any keyboard input by me) the character doesn’t actually move along the spline but just runs on the spot.

            3. I get two errors when compiling the character blueprint:
            Input Axis Event references unknown axis LookUp

            I’ve also tried the event tick node for movement with no luck.

            I have attached several screen shots here:
            https://www.dropbox.com/s/s4q13v657fbfbk9/spline_query.zip?dl=0

            Any help with this would be great

  2. Hey so I followed everything and nothing happens, my thirdpersoncharacter just stands there. Also you don’t explain how to get that last SET in the last blueprint of Spline BP, so I can’t connect self to anything.

    1. You need to create a variable Spline BP in your Spline Blueprint. And on its beginplay method, asssign the self reference to the variable you created. Let me know about errors you are facing with this.
      Thanks

      1. So I created the variable in my spline blueprint like your steps says but the only way I was able to get that Set at the end I had to uncheck content sensitivity. But now I can’t link as third person character to target.

        http://imgur.com/0aOawJC

        I named my third person chararacter blueprint Enemy AI, shown in the picture

          1. You are using Player controller reference , to cast it to AI controller, so it is showing WARNING . What you can do here is search for “Get Controller” instead of get player Controller, then you will be able to cast it without any warning as AI COntroller is child of Controller class. @ Geoffrey

        1. You have to set value of Spline variable inside your Character BP. So drag wire from third person cast node and search for SPlineBP and select variable from there. Right now, the SPline Path variable inside your blueprint doesn’t seems to be belonging to Character Blueprint.

  3. @Joey Yes we can make AI bot to follow the path. I currently don’t have the screenshots. But I will surely create one and will add here. And so sorry for late response !!

    1. Hello PlayBlood. You need to connect your axis value (inside MoveRight) to the scale value (Inside Add Movement Input).
      To move forward you need to add MoveForward node.

      Let me know if you still face some problem.

      Thanks

        1. I solved the character penetration with the floor, the Z axis of the spline must be set at the same Z axis of character pivot. For the movement problem i dont solve anything…

      1. It worked, thx! But now there is another problem 🙁 When I hit play he just stay like this http://imgur.com/iw6TXhC
        And when I press to walk he just move his legs without going anywhere. ( Actually I have to make just the camera follow the spline path, there is another way to do it?)

  4. Hi,

    thanks for this, its been very helpful.. however I can’t work out how to make it work on non player characters, either one dropped in the scene or with a pawn.. I can’t seem to have a cast to pawn set the splineBP or use anything other then GetPlayerCharacter going into the Cast to ThirdPersonCharacter

  5. I was wondering there is a way to have a character not only follow a spline, but multiple splines? For instance; an intersection point of two splines and the player would have the choice of which spline to follow after the decision has been made. This would of course involve rotation, but just wanted to know if that would even be possible. Thank you for the tutorial, very helpful!

  6. Hi!!!

    I have some problems. The character appears to be running immediately (without any keyboard input by me).

    How I can resolve this problems. Tahnks

  7. Thank you very much for this tutorial… 🙂
    Unfortunately; I had the same problem Patrick had mentioned above…
    When click Play; My character didn’t move along the spline , it just jumped to a place & stayed at there [without any relation to the path (SplineBP) I had created] and got an Error Message…

    See images please

    SplineBP Blueprint
    http://imgur.com/PmIRJY7
    http://imgur.com/CeBMKIg

    Character Blueprint
    http://imgur.com/worIoQ4

    Error Message
    http://imgur.com/mjEpX7w

    I hope someone may push an advice to fix my problem
    Thank you ..!

  8. Is there a way to change the spline that character moves along? like If I wanted the player to make a choice in a fork in the road and if he chooses right he will follow along the right path instead of the left and vice versa?

    1. @Sean !
      I don’t know if it is allowable to post youtube links in this post..?
      Instead; I suggest to send me an email to (saad_cad at yahoo dot com), requesting the link in which you may find a free ue4 project that fits your needs..!!
      Regards

  9. A picture showing the whole blueprint and where they connect would help, i have no idea where to connect some of the stuff

    1. I may have commented too fast woops, i found the pic of the whole bp. Is there a way to make it so that when you jump on the spline it moves you from where you landed. Its for a grind in skating game. currently it puts you to the strt of the spline no matter where you land.

    2. Also, I made a grind blueprint with the spline in it. it works fine but if i try place a second instance of the blueprint it either teleports to the other one or only one works. Any help?

Leave a Reply

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