How to garbage collect USTRUCTs?

anonymous_user_7a9aff17
Sat, 12 Jul 2014 08:03:36 +0000
Editor Scripting

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.

2 posts - 1 participant