Hi, I am new to UE and C++, By what I understood from c++ [intro page][1] , UObjects which are not marked with UPROPERTY will get GCed. here is the ScreenShot of the page.
I wrote one experiment code to understand this which looks like this:
UPROPERTY()
UObject *obj1;
UObject *obj2;
float time;
// Sets default values for this component's properties
UWaveActor::UWaveActor()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
obj1 = NewObject<UObject>();
obj2 = NewObject<UObject>();
// ...
}
// Called every frame
void UWaveActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
if (obj2 != nullptr)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
AActor *ad = GetOwner();
FVector pos = ad->GetActorLocation();
time += DeltaTime;
pos.Z = FMath::Sin(time)*5.0f;
ad->SetActorLocation(pos);
}
}
and called GEngine->ForceGarbageCollection(true) from another actor component, which should destroy obj2 but the actor is still animating so obj2 is not destroyed. I misunderstood something or missing something, any help will be appreciated.