Skip to the bottom if you just want the c++ code to use.
Originally written for 4.9. Updated 2016-09-05 for 4.13 (also maybe .10, .11 and .12) code changes.
After following the great tutorials on using splines and spline meshes by DokipenTechTutorials I had a very useable spline_path object, but wanted to extend it a little further. I re-implemented some existing blueprints I was using elsewhere and created options that let me auto-height and auto-pitch start, middle and end points to follow the shape of the ground or object underneath the spline.
However when it came time to set the roll of the spline points, I found there was no blueprint node for it! Existing posts on answerhub and the forums had suggestions of setting the roll on the child splinemesh objects, but I’d already configured that to follow the roll of the spline itself which I wanted to keep:
And I found that the roll of the splinepoints could successfully be set in the editor, so there was code somewhere that was allowing it:
I looked through SplineComponent.h and SplineComponent.cpp which showed that rotation data was stored in SplineRotInfo as quaternions:
And looked through SplineComponentVisualizer.cpp for any references to rotation, where I found this section:
Pulling together all the declarations, and letting previously defined code do all the heavy lifting I was able to put together a blueprint callable function in a C++ blueprint function library as follows:
Create a new c++ blueprint function library and implement the following code. For this your project will need to be code-enabled. Use “File > Add Code To Project” if you haven’t done this already.
Once you’ve added the blueprint function library, implement the following code (pastebin links below images):
.h file:
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Components/SplineComponent.h"
#include "spline_extensions.generated.h"
/**
*
*/
UCLASS()
class TROPICALMANIPULATION_API Uspline_extensions : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/* Sets the rotation on a spline point Local rotation only.*/
UFUNCTION(BlueprintCallable, Category = "Splines") //make the function usable in blueprints. BlueprintPure doesn't require exec; BlueprintCallable does.
static void set_rotation_at_spline_point(USplineComponent* target, const int32 point_index, const FRotator rotation); //define inputs and outputs. Const for inputs, and & for outputs.
};
.cpp file:
2016-09-05 UPDATE: SplineRotInfo has been deprecated. Use GetSplinePointsRotation() instead. The text has been updated.
#include "TropicalManipulation.h"
#include "spline_extensions.h"
#include <cstdlib>
void Uspline_extensions::set_rotation_at_spline_point(USplineComponent* target, const int32 point_index, const FRotator rotation) //exactly the same as in .h but without 'static' and with Uspline_extensions:: in front of the function name
{
FInterpCurveQuat& SplineRotInfo = target->GetSplinePointsRotation(); //get the array of rotation data in the spline component
FInterpCurvePoint<FQuat>& EditedRotPoint = SplineRotInfo.Points[point_index]; //get the point to edit
FQuat NewRot = rotation.Quaternion(); //convert the given rotation into a quaternion
EditedRotPoint.OutVal = NewRot; //set the new rotation of the selected point
}
Note: make sure you update the copied code to match your project and blueprint function library - lines like ‘class TROPICALMANIPULATION_API’ and ‘void Uspline_extensions’ need to be changed.
Compile (ctrl + shift + B), and if you’ve done everything right you should now be able to add a node to set the rotation:
Usage is similar to other spline nodes: specify the spline and point to edit, and the rotation to set. Rotation is local.
Enjoy!
Twitter for updates and cool things.
Videogames
Hey, do you like videogames? If so please check out my game Grab n' Throw on Steam, and add it to your wishlist. One gamemode is like golf but on a 256 km^2 landscape, with huge throw power, powerups, and a moving hole. Another is like dodgeball crossed with soccer except instead of balls you throw stacks of your own teammates. And there's plenty more!See full gameplay on Steam!