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

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 ph...

Updated over 1 year ago Edit Page Revisions

Overview

Author: Rama

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.png

UE4 Curve Asset

MiscCurve.png

UE4 Curve Editor

CurveAuto.png

.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.png

Conclusion

Enjoy!