How do I create an UCurveFloat?

Hi
I have very simple question: how I can create UCurveFloat ? My question derives from setting up my own FVehicleEngineData and the last part I am missing is TorqueCurve. Thanks in advance for any clue.

This goes in a few steps, likely.

  1. Create data points:

    auto richCurve = new FRichCurve();  
    auto key = richCurve->AddKey(0.f, 0.f);  
    richCurve->AddKey(0.5f, 1.f);  
    richCurve->AddKey(1.5f, 0.f);  
    richCurve->SetKeyTime(key, 10.0f);  
    richCurve->SetKeyInterpMode(key, RCIM_Linear);  
    
  2. Create curve object itself

    auto curve = NewObject<UCurveFloat>();
    
  3. Add data to curve

    auto list= curve->GetCurves();  
    list.Add(FRichCurveEditInfo(richCurve, FName{ TEXT("SomeCurveName") } ));
    
  4. Add to Timeline (assuming you have progressFunction initialized)

    timeline.AddInterpFloat(curve, progressFunction, FName{ TEXT("EFFECT_TIMED") });
1 Like

Hi,
Will these code create memory leak?

auto richCurve = new FRichCurve();

And never delete

Lifecycle management was not a part of this question, sorry. :slight_smile:

As FRichCurve is not handled by GC (not a part of UObjectBase etc) it has to be going through new/delete.
Actually, if you take a look into Engine Source Code you may find a lot of similar new-based allocations.
Like in CurveTable.cpp (Runtime/Engine/Private/) etc

So there are two ways - release it somewhere manually or have it added to a container that would manage lifecycle.

@robodrunk’s answer works, but instead of

auto list= curve->GetCurves();  
     list.Add(FRichCurveEditInfo(richCurve, FName{ TEXT("SomeCurveName") } ));

just:

curve->FloatCurve = *richCurve;
1 Like