Actor following spline (4.5)

Firstly, excuse my english mistakes in grammar or syntax (if I have some). Secondly I would explain my problem, that I have no idea how to solve.
What I want to do, is to make some actor following a path of pre-defined splines (included in specific actor blueprints).
In this picture, you can see how these splines are set:


It’s not just one spline… All splines you can see in this pic are just a combination of parts of the path. For example, you can see only the first spline:


And these splines are included right in the scene as children of Landscape, that you can see on this picture: (They are called “Cesta”, which in Czech language means “Road or Path”)


The blueprint actor (Cesta) has only one component (spline), where you can’t actually see the shapes and points.


And here comes the problem. I have another simple Character blueprint and I want it to follow the splines. I want to create an array of scene components, which will be a “sequence”, that says, which spline the actor has to follow after “finishing” the previous one and also to create a script, that will move this component right the way of the path. I hope you understood me and sorry if there is something unclear. I will try to answer any question.
Thank you

Are these spline roads procedurally created, set by hand, etc?

If you know exactly how each intersection is laid out, it should be a simple problem of follow spline, reach end, choose first spline point from one of the next available splines(like an array of spline start points for each intersection), and so on.

If you don’t know what splines are going to be at what intersections due to procedural generation, then it gets quite a bit more complicated.

Well, you should probably know that I’m not a professional, so maybe some of the things I made in my project are just “wrong”. These splines are set by hand… I made an actor blueprint called “Cesta”. I opened it in a blueprint editor and added spline component in it. Saved, compiled and dragged and dropped into my scene (placed on the map). Even though you can see multiple actors in my scene outliner panel - they are the same blueprint. I didn’t make one BP for every path (maybe that’s a wrong way). When I had these actors in my scene I started modifying them into the shapes of the roads on the map. Using ALT key and extending existing points I added points right in the scene. I tried to make the ending points and starting points of different (connected) splines to have the same coordinates. I don’t know how to get the locations of the points on a specific spline. Maybe if I would know how to do this, than I can cope it. I just want to find a vector between two points of a spline (set in scene).

Maybe I will do it a different way… I will create objects which will represent something like “checkpoints” and I will be only looking for their positions. Then I will easily get the vector between two point actors. To move something somewhere is easy if I have vector. But how can I get a position of an object in game?

Objects have names in your scene outliner, so you should be able to use that name as your reference in blueprint. I do things a little differently in that I procedurally generate everything from blueprint so I store the reference as I spawn it.

You could probably do the same thing. Mark down the vector where you want each spline point and then use those vectors to spawn your splines. Then when you spawn it you already have the object reference and all the vectors.

I don’t actually need splines to move the actor… I need only the points, where the moving character changes its orientation. Spline would be better solution only if I need the “shape” of the path between two points. But on such a small scale there is almost no difference between linear spline a curved spline (if I use enough points). And what about the reference… I can use the reference only in my Level BP (when I drag and drop the object from the scene outliner to the BP graph). Maybe it’s a bug or my bad, but I am not able to do this with an actor blueprint. If you don’t mind, would you please send me a pic of you making a reference to an scene object in some actor blueprint?

If you haven’t already I would highly advise following Dokipen’s tutorial: [TUTORIAL] Create a procedural spline road tool in blueprints 4 part video series - Community Content, Tools and Tutorials - Unreal Engine Forums

Even if you don’t necessarily need the mesh bending parts, there should be enough there to get you rolling with splines in general.

Thanks for the tutorial… I think it’s usefull and I will use it sometimes. However it doesn’t solve my problem. I don’t have a problem with creating a road as a mesh or a physical object. My problem is that I want an actor to follow the spline while moving in a game. Not to create an object “transformed” to the spline. Imagine a situation, that you have a train. The problem is not to create railroad, but to stick the train to that railroad (to keep that train off the danger of derailment).

I think I’m now working on something, that might work… But for testing it I need to create public accessable variables. I would like to create it in my level BP, but I don’t know how to access it from antoher blueprint. Can you help me? I have simple objects, that represent points, where the character changes the vector, that shows which direction it should move. Then the character keeps moving until it “hits” another (preselected) one. After that it changes that vector and goes again. It’s repeating until the character reach the destination point. But the problem is, that I use node “Get All Actors Of Class”. And it gets the right actors, but they’re unsorted for me. I need to create an public array, that will contain the sequence (which one goes first, which one goes second, etc.). I want to create it in levelBP, but I don’t know how to access it in my actor blueprint.

Have you seen the spline section in the content examples you can download from Epic? They have a spline track set up with a little ball of light following along. That might have what you need.

I couldn’t find it. However I’ve already solved my problem (basically). I used that Dokipen’s tutorial to create a spline that “spawns” my BPs (representing checkpoints) every 50 units. Then I made a BPscript in my Character. This scripts finds ALL actor of class “Checkpoint” and I can work with them. The problem is, that the node “Get All Actor Of Class” doesn’t find these checkpoints** in order I need**. So my Character walks over the map from checkpoint to checkpoint, but “randomly”. I need to create a seperated array that will contain the order of checkpoints. But I don’t know how to create Global Variable (or something like this) in Unreal… I need to create this in a seperated blueprint, because player will be able to change the order and all actors in the game must follow this order.

I try to understand blueprint interfaces, but I can’t find out, how to share one variable between two blueprints with this. I found only videos, where it’s used for moving objects, when you shoot at them. I don’t know how to use it for sharing a variable.

//EDIT 2:
I found better solution then interfaces… It’s made by custom event. All I got is from this video:

But instead of pressing F key I used Event Begin Play, but I could use Event Tick and I have a variable that can be set and immediatly “send” to blueprint, where I need it.
Maybe if I will have enough time, I’ll make whole tutorial for creating custom path road.

Maybe everything I was trying to was useless… I drunk something and got an idea :smiley: IT WAS SO EASY!! :smiley: Take a look:

There is a small problem (of course)… I know where the problem is. That node “Get World Location at Distance Along Spline” is expecting Spline Component input and it’s obvious, that the output from “Get Components by Class” will be Spline Component, but it might be whatever (in different cases). What should I do?
BTW: I know I should connect an increasing variable to “Distance” input at “Get World Location at Distance Along Spline”