I am getting an error when the garbage collector is called on my timeline.
In my header file, I have declared an array for my timelines
UPROPERTY(BlueprintReadWrite, Category = "FalParserAnimInstance")
TArray<FTimeline> FacialTimelines;
In my cpp file, I add timelines every so often
FacialTimelines.Add(FTimeline());
FTimeline* currentTimeline = &FacialTimelines[FacialTimelines.Num() - 1];
currentTimeline->AddInterpFloat(curveFloat, FOnTimelineFloat(), FName(*keyFrame.sTargetBoneName));
currentTimeline->PlayFromStart();
To force a garbage collection I called (the error still occurs when garbage collection is called by the engine itself)
GetWorld()->ForceGarbageCollection(true);
However I get the following error, when garbage collection is called
Invalid object in GC: 0xcccccccccccccccc, ReferencingObject: FBAB_MikuDreamFighter3_C /Game/Maps/UEDPIE_0_Default.Default:PersistentLevel.Miku_5.SkeletalMeshComponent0.FBAB_MikuDreamFighter3_C_2, ReferencingProperty: ObjectProperty /Script/Engine.TimelineComponent:Timeline.DirectionProperty
From some of the other posts, I’m guessing that the error occurs because garbage collection needs to go through each component of the timeline, however some parts contain garbage data that was not initialized properly.
If this is the case, how do I properly initialize a timeline?
I think I’m supposed to initialize a timeline like the following
FTimeline* currentTimeline = NewObject<FTimeline>(this);
currentTimeline->AddInterpFloat(curveFloat, FOnTimelineFloat(), FName(*keyFrame.sTargetBoneName));
currentTimeline->PlayFromStart();
FacialTimelines.Add(*currentTimeline);
However, I am not doing it correctly and get the following error
1>y:\uesource\unrealengine\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(1027): error C3861: 'StaticClass': identifier not found
1> -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: Y:\MMD\Unreal Engine\UnrealProjects\MikuCode\Binaries\Win64\UE4Editor-MikuCode-Win64-Debug.pdb
I also try to remove the timer in the following way
if (FacialTimelines[i].IsPlaying())
{
// code
}
else
{
// remove the timeline if it is no longer playing
FacialTimelines.RemoveAt(i);
// TODO REMOVE DEBUG
GetWorld()->ForceGarbageCollection(true);
}
How do I properly initialize a timer, and how do I properly get it garbage collected when I no longer need the timer and want to deallocate it?