Adding FTimeLine in c++ causes editor to crash

I am following this example to add timeline to my c++ code How to create a Timeline in C++? - Programming & Scripting - Epic Developer Community Forums
And in constructor when I add this code

const ConstructorHelpers::FObjectFinder<UCurveFloat> curve(TEXT("CurveFloat'/Game/Spline/SpeedCurve.SpeedCurve'"));
    	timeLine = FTimeline{};
    	FOnTimelineFloat processFunction{};
    	processFunction.BindUFunction(this, "UpdateTimeLine");
    	timeLine.AddInterpFloat(curve.Object, processFunction, FName{TEXT("SPEEDCURVE")});

And compile it, it crashes.

Here is the crash report

MachineId:B91038F04A1F0FC8835004955799C600
UserName:papatel

Unknown exception - code 00000001 (first/second chance not available)

Fatal error: [File:D:\UnrealProjects\UnrealSource\UnrealClone\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp] [Line: 273] 
Invalid object in GC: 0x0000000013dc5e80, ReferencingObject: AIVehicle //Script//CrowdA

KERNELBASE + 40541 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 285 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FMsg::Logf__VA() + 463 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\misc\outputdevice.cpp:526]
UE4Editor_CoreUObject!FGCCollector::HandleObjectReference() + 280 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\garbagecollection.cpp:270]
UE4Editor_CoreUObject!FSimpleObjectReferenceCollectorArchive::operator<<() + 77 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\public\uobject\garbagecollection.h:460]
UE4Editor_CoreUObject!UObjectProperty::SerializeItem() + 55 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\propertyobject.cpp:23]
UE4Editor_CoreUObject!UStruct::SerializeBin() + 222 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\class.cpp:674]
UE4Editor_CoreUObject!UStructProperty::SerializeItem() + 433 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\propertystruct.cpp:119]
UE4Editor_CoreUObject!UStruct::SerializeBin() + 222 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\class.cpp:674]
UE4Editor_CoreUObject!UObject::SerializeScriptProperties() + 426 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\obj.cpp:897]
UE4Editor_CoreUObject!UObject::AddReferencedObjects() + 342 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\garbagecollection.cpp:1222]
UE4Editor_CoreUObject!FArchiveRealtimeGC::ProcessObjectArray() + 7245 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\coreuobject\private\uobject\garbagecollection.cpp:706]
UE4Editor_CoreUObject!TGraphTask<FArchiveRealtimeGC::FGCTask>::ExecuteTask() + 442 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\public\async\taskgraphinterfaces.h:671]
UE4Editor_Core!FTaskThread::ProcessTasks() + 2979 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\async\taskgraph.cpp:428]
UE4Editor_Core!FTaskThread::ProcessTasksUntilQuit() + 77 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\async\taskgraph.cpp:271]
UE4Editor_Core!FTaskThread::Run() + 11 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\async\taskgraph.cpp:562]
UE4Editor_Core!FRunnableThreadWin::Run() + 86 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:73]
UE4Editor_Core!FRunnableThreadWin::GuardedRun() + 93 bytes [d:\unrealprojects\unrealsource\unrealclone\unrealengine\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:26]
kernel32 + 91437 bytes
ntdll + 181569 bytes

I don’t know what I am doing wrong here,

THanks,

Hey buddy! I had a similar problem. Mine crashes in begin play.

First, I would tell you to place this line in begin play(), not in the constructor:

timeLine.AddInterpFloat(curve.Object, processFunction, FName{TEXT(“SPEEDCURVE”)});

Secondly, this line:

const ConstructorHelpers::FObjectFinder curve(TEXT(“CurveFloat’/Game/Spline/SpeedCurve.SpeedCurve’”));

Im not sure why for the file path youre using a ’ before /Game. And after SpeedCurve.

It looks like perhaps it should look like this:

(“CurveFloat/Game/Spline/SpeedCurve.SpeedCurve”));

In any case, have you debugged and checked that curve is not null? It will be null if the path you entered was wrong. This will make the AddInterpFloat fail and crash the editor.

I suggest you debug and use a check like this:

if(curve.Object)

{
timeLine.AddInterpFloat(curve.Object, processFunction, FName{TEXT(“SPEEDCURVE”)});
}

Again, this check and this addInterp, should go in beginPlay().

I really hope it helps man. Let me know if you find a solution to it. Best of luck!

Ok Im sorry you cannot use curve.Object in the beginPlay cause it will tell you its an undeclared identifier.

Instead the answer would be to declare a variable like this one.

UPROPERTY()
UCurveFloat* fCurve;

then in the constructor do:

if(curve.object)
{
fCurve = curve.Object;
}

then in beginPlay() do this:

timeLine.AddInterpFloat(fCurve, processFunction, FName{TEXT(“SPEEDCURVE”)});