Can runtime curves be exposed to blueprints, please?

Runtime curves seem to be super useful, but for whatever reason they haven’t been exposed to blueprint yet. Please, can this happen already?

Currently you can add a runtime curve variable (float and vector) in blueprints, but there are no functions exposed to edit or evaluate these curves. You can only edit the curve in the details panel, but then not be able to use it for anything.

Have you looked at the curve assets and how they are used?

Yes, and I can’t use them for what I need. Can’t create and edit them programmatically at runtime.

EDIT: I don’t even think curve assets can be edited programmatically in the editor either, at least not exposed to blueprints.

1 Like

Well, what do you need exactly?

Afterall a curve is basically just an equation / a set of points.

If you need something that is both visual and codable, its a bit of work, but you may be able to just levarage a spline for visual…

the big reason that Curves are not exposed for modification to code (in Blueprints or C++) is because they are more then just the set points on the curve, the slopes are pre-calculated as well. and anything dealing with curve fitting can take a bit of computational power, and it could delay the main thread either by being on the main thread, or being in a race-condition to the main thread.

there are some work-around(s) you can try:
*setup a Curve Data Table with multiple curves defined, this way you can pick and choose which one you want to use based on the situation. they will all need the same type of behavior for the special points, but it will allow for defining multiple in the same Asset.
*figure out the general form of the equation defining the curve on the given range; which will require understanding the slope intercept form of the given curve you want and then feeding the special “constants” in along with the X value (for example a Quadratic behavior would be A(Bx-C)^2 + D, and you will quickly realize why even heavy math people would still prefer to work with the curve editor, and why graph type things are done in blueprints for even heavy C++ projects)

tl;dr: massive +1 Vote


Judging by the tone in this thread, I feel like the posters above never felt the need to take advantage of run-time curves, at least not in BPs. Perhaps they’re C++ proficient enough to never have to look back at what BPs cannot do. :innocent:

Those curves already worked with some components in UE4 but were not directly exposed as stand alone objects to BPs afair.

I believe I asked a similar questions a couple of years ago.

It’s a bummer UE5 now supports editing them, just like that, but provides no way to even evaluate their data. You could add a tiny bit of C++:

UFUNCTION(BlueprintPure, Category = "Math|RuntimeFloatCurve")
	static float GetRuntimeFloatCurveValue(const FRuntimeFloatCurve& InCurve, float InTime);
float UMyFunctionLibrary::GetRuntimeFloatCurveValue(const FRuntimeFloatCurve& InCurve, float InTime)
{
	// Evaluate the curve
	return InCurve.GetRichCurveConst()->Eval(InTime);
}

Which at least gives you:

At this point, it’s just a more convenient curve editor, hardly run-time.


So, yeah, again: +1

1 Like

I’m making a Scriptable Tool to create static mesh assets using Geometry Script which for now is editor only. The part I need the curve for I might do at runtime later for something different, but either way for now the curve needs to be programmatically created from interacting with the Scriptable Tool. I don’t need the visual of it since I’m already handling what I need on that front through the Scriptable Tool.

Now, I have been using a spline component for what I’m wanting this for, however it’s not as accurate as I’d like. I’m specifically wanting it for what I think would be called a one dimensional curve, so like at X time get Y value much like the “Get Float Value” works for curve assets. With a spline component the X time is the distance along the spline rather than the distance along the X axis, and so it’s warped by the curvature of the spline making it less accurate than I wish it were. Plus, with a spline component it’s possible to do loops and double back on itself which can only further mess with things.

In this case specifically I suppose I could get by with a blueprint function to evaluate a curve which only has two points with tangents, so if you know what that would look like in blueprints I’d appreciate it. However, runtime curves seem like exactly what I’m looking for, and I wouldn’t have needed to ask anyone for help if runtime curve functions were exposed to blueprint in the first place.

So then would it be heavier than using a spline component? Either way, doing it entirely in blueprint would just make it perform even worse that it would otherwise, right?

image

Not sure I follow but wouldn’t it be a matter of using constant velocity. :point_up: This would give you even distribution regardless of the position of the spline points.

So, you can assume the coords for the 2 points are always
0,0 and 1,1
This leaves you with 2 points (4 values) that you need to create the handles.

A linear curve would mean
0,0 and 1,1,
Again.

anything else is where the points move out
0,.5 and 1,.5
Would look something like a squiggled s.

Probably, you want to be able to support a variety of implementation, so you need to refractor the thinking in a ± range
-1,-1 to 1,1
Realistically the definition is just about the same you only need to save and know the 2 x/y of each or the 2 tangents.

Given that, you can then apply the math to filter the end result in some meaningful way. Likely using bezier.

What I’m missing in this, is the end use right?

You need some system making use of the x/y value along the curve you define.

So you define the points that make up the curve, but then you need to implement the function that collects the point location for your X along the curve.
Or Y - or both?

I have only really worked with runtime stuff on this, and mostly by getting x/y at gametime - gametime being what powers the repeating sine based curve in my case.

IIt’s completely poissible for you to create the bezier function to solve either x or y in BP.
The speed you get computation wise won’t be great, but if it is an editor tool it also won’t really matter?

Granted it is an atan driven rabbit hole, but i think you can break open the formula off wikipedia and try your hand at solving the math in BP.

Alternatively, I’d look into the existing c++ kismet to see if a function in C++ to solve for the point value you want is already a thing.
Its easier to read than mathematic notations Unless you eat math books for breakfast or something…

ps:
From above

The curve is the definition, and time is the X on the graph.
You can probably pull some idea out of that - though linear…

I had a similar task. I was need to edit the existing curve table from a blueprint. This is the method I’v added to the library. Now I may call it from a blueprint to construct the curve.
The code:

h:
UCLASS()
class P001GAME_API UP001DataTableFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:	

	UFUNCTION(BlueprintCallable, Category = "P001")
	static bool AddRowToRichCurveTable(UCurveTable* Table, FName RowName, TArray<float> Keys, TArray<float> Values);
};

//-------------------

cpp:

bool UP001DataTableFunctionLibrary::AddRowToRichCurveTable(UCurveTable* Table, FName RowName, TArray<float> Keys, TArray<float> Values)
{
	if (!Table)
	{
		return false;		
	}


	FRichCurve& RichCurve = Table-> AddRichCurve(RowName);
	RichCurve.Reset();
	for (int i = 0; i < Keys.Num() && i < Values.Num(); ++i)
	{
		RichCurve.AddKey(Keys[i], Values[i]);		
	}
	
	return true;
}

1 Like