Anim blueprint and threadsafe curve?

I have a variable in my animation blueprint set to a curve object for reusability. But when trying to access “get float value” for the curve the compiler complains about it not being thread safe.
Some posts I have found suggest to use the property access node for such cases but it doesn’t seem to work with the curve variable as the compiler still complains.
Any way around this compiler issue while using standalone custom curves?

2 Likes

bump

i was able to cobble something together to make this happen. I’m uncertain of the best approach.

A: Wrap the source UCurveFloat in a struct and create C++ ‘thread safe’ function to do the GetFloatValue
B: Wrap the underlying UCurveFloat:RichCurve and create C++ ‘thread safe’ function and use ‘Eval’ on FRichCurve

I can confirm B is good, but haven’t tried A yet.

Either way, basically wrap a C++ struct around the underlying FRichCurve that come from UCurveFloat. You can inspect UCurveFloat and see it’s just accessing a struct under the hood.

Coding Requirements:

  1. Add a struct in C++ that will contain the curve data.
USTRUCT(BlueprintType)
struct FThreadSafeCurveContainer
{
	GENERATED_BODY()

	FRichCurve RichCurve;
	
};
  1. Add/or append to a BlueprintFunctionLibrary, the following functions:
UCLASS()
class MYGAME_API UAnimationFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:

	UFUNCTION(BlueprintCallable, Category = "Utility|ThreadSafeCurve")
	static FThreadSafeCurveContainer MakeThreadSafeFloatCurve(const UCurveFloat* Curve);

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Utility|ThreadSafeCurve", meta=(BlueprintThreadSafe))
	static float GetFloatValueFromThreadSafeCurveContainer(const FThreadSafeCurveContainer& CurveContainer, const float& InTime);
}


FThreadSafeCurveContainer UAnimationFunctionLibrary::MakeThreadSafeFloatCurve(const UCurveFloat* Curve)
{
	return {Curve->FloatCurve};
}

float UAnimationFunctionLibrary::GetFloatValueFromThreadSafeCurveContainer(const FThreadSafeCurveContainer& CurveContainer, const float& InTime)
{
	return CurveContainer.RichCurve.Eval(InTime);
}

  1. and with that, in BP, convert the source curve into the new thread safe container (store it somewhere that is accessible to the AnimBP…)

  1. in the AnimBP BlueprintThreadSafeUpdateAnimation function, GetFloatValueFromThreadSafeCurveContainer is now available and can get that curve value

image

1 Like