Feeling inspired to find a solution to this, I decided to make a project to figure it out, and have come up with a proof of concept solution. Meaning, it could be cleaner or have unwanted functionality, but it basically works.
Basically a spline is added to a Spline Actor and is one direction only. When the spline reaches what is supposed to be a branching point, it just stops there and two or more new Spline Actors are added to the editor. A (T)Map is then used to determine which Spline Actor is referenced in which direction.
So the Map key is an Enum (Stop, up, down, left, right) and the value is a reference to the Spline Actor.
(In case you don’t know, by selecting a variable and checking “instance Editable”, you can in the editor select the Spline Actor and then allow that instance to have a reference to other instances.)
So the player makes an input which is saved as a direction, the Pawn gets a reference to the next Spline Actor and starts following that instead.
As some additional things, I created a Default Direction variable to the Spline Actor so that if the player makes no input, the Pawn just continues in the default direction.
The Stop Enum is there if the pawn should stop at a fork, waiting for player input, instead of continuing on the default path.
It’s not much code but had to take 3 screenshots.
A few things to note:
-The way the pawn is moved along the spline is by resetting a float when a new spline is to be moved along, then adding the tick float to it every frame. This is just for me to get the pawn to move along the spline and may not be what you are doing.
-I ended up using 3 different enums for the various directions (directions [Up, Down, Left, Right], Spline Actor Directions[Stop, Up, Down, Left, Right], Player input[None, Up, Down, Left, Right]) and can probably be replaced with a single one.
-The way that it is determined if the pawn has actually reached the end of a spline is by comparing the splines length with the move time, with some tolerance. Maybe that’s not good enough.
- In the editor screenshot, the arrows shows the splines and Spline Actors have been slightly separated to show that there are actually several actors, not several splines in one actor. Though thinking about it now, that’s probably possible too and would be very similar to the current solution.