I am having a hard time understanding how to delete UStructs. Unlike UObjects, they are not handled by Unreal’s garbage collection system (is this correct?) and we are supposed to delete all dynamically created UStructs manually. However, there are some occasions when I can’t think of the right time to delete them. Consider the damage code:
float AMyCharacter::TakeDamage(
float DamageAmount,
struct FDamageEvent const& DamageEvent, ... )
Here, FDamageEvent, which is an UStruct, is passed by reference, so the object which created it is responsible for deleting it. But how long will it stay there? For example, I might want to store an array of UStruct pointers for damage over time mechanics, or maybe it’s better to just copy the data and never use pointers.
What will happen if I use shared pointers here?
TSharedRef<FEternalDOTEvent> DmgEvRef(&DamageEvent);
And if I pass UStruct* from Blueprints, will these ever get GC’ed? Sorry for having done little research on this, but I really need to get it working without crashing or memory leaks.