Curves, Create Custom Cubic Curves In Editor For Use In Code

From Epic Wiki

Overview

Author: ( )

This wiki tutorial shows you how to get custom hand crafted curves into C++ !

This uses a combination of UE4 blueprints and UE4 c++ to enable you to create custom effects and physics movement curves in pure C++ with the ease of UE4's visual curve editor!

Below is a picture of the final result!

I draw this curve in the editor and and can now use it in C++ !

CurveFinal.jpg

UE4 Curve Asset

MiscCurve.jpg

UE4 Curve Editor

CurveAuto.jpg

.h

UCLASS()
class AYourCharacter : public ACharacter
{
	GENERATED_UCLASS_BODY()


	/** Joy Curve */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="JoyCurve")
	UCurveFloat* JoyCurve;    
	
	
	//Rama's Draw Point wrapper
	FORCEINLINE void DrawPoint 
	(
		const FVector& Loc,
		const float Size = 7,
		const FColor& Color = FColor::Red,
		const float Duration=-1.f
	) const {
		DrawDebugPoint(
			GetWorld(), 
			Loc,  
			Size, //thickness
			Color, 
			false,
			Duration
		);
	}

.cpp

//Tick
void AYourCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//~~~~~~~~~~~~
	
	
	//~~~ Draw the Curve! ~~~

	if(JoyCurve)
	{
		for(float v = 0; v < 1; v+=0.01)
		{
			DrawPoint(GetActorLocation() + FVector(v * 128,0,128 * JoyCurve->GetFloatValue(v)) );
		}
	}
	else
	{
		//UE_LOG "Joy CURVE IS INVALID!!!!";
	}
}

Character BP

Compile the above addition to your Character class!

Now set the asset reference that you made in the code, in the editor in your character BP!

CharBP.jpg

Conclusion

Enjoy!

( )