About UObject dynamically create and delete

Hi guys,

I have a question about new a UObject (using ConstructObject). If the UObject variable does not use UPROPERTY or it is a UObject pointer in a function, after I “ConstructObject” the UObject. will it be GC automatically or it will in memory I delete it manually?

Also, When I load resource such as static mesh, texture or blueprint from hard drive using something like “StaticLoadObject”, How to maintain the lifetime of these loaded UObjects (may be UBlueprint, UClass, UStaticMesh)? How to keep them available? Will it be GC or do I have to delete it explicitly?

If it’s not UPROPERTY, Unreal will not know about it. If you don’t mark it as UPROPERTY, you can help Unreal figure out references by implementing AddReferencedObjects. Essentially (from my understanding) it uses that static method to figure out unmarked dependencies between your host object and created UObjects - so essentially you are implementing your own UPROPERTY. You also should not delete UObjects with delete. Use ConditionalBeginDestroy / BeginDestroy.