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.
-
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);
-
Create curve object itself
auto curve = NewObject<UCurveFloat>();
-
Add data to curve
auto list= curve->GetCurves(); list.Add(FRichCurveEditInfo(richCurve, FName{ TEXT("SomeCurveName") } ));
-
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.
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