I have an array of 3d widget actors, I want to delete all of them (not set them as hidden). I am getting no errors or anything, just nothing happens except the array being cleared when the code below is ran (and variations mentioned in comments).
Yes it’s an actor blueprint with a widget scene component.
The array does get cleared.
My test to determine if they are deleted or not is using get all actors of class → for each → print, (The array is expected to be 8 long, and after populating, clearing, repopulating it increases by 8 to 16, 24, 32, etc. and you can see the 3d widgets piling up while playing in editor.
I populate the array when they’re created in the same blueprint,
The issue isn’t that the references are bad. I can set the 3d widgets to be hidden, and I can modify the text the widget displays until I clear, then repopulate the array, at which point only the most recent set can be modified.
Ah, so they do disappear visually but they are not being Garbage Collected? Note that the GC clumps actors together before releasing them from memory, flags them as Pending Kill and only then removes them in batches. It may take a while for this to happen for efficiency reasons.
Assuming their onDestroyed do trigger:
keep printing the array length for a minute - see if the actors actually go away, do they?
or call Collect Garbage after the loop Completes and after you’ve Cleared the array
do read this node’s tooltip to see what you’re dealing with
Or check how many of the returned Out Actors are actually Valid references; anything waiting in the queue to be destroyed should be invalid / throwing Accessed None / Pending Kill errors. But it will still show up in the array, affecting its size.
Not directly applicable here but somewhat related: the above behaviour is painfully obvious when dealing with regular 2d widgets since there’s no Destroy call exposed to BPs, and we must wait for the GC to do its job - and it takes a while. This was a major source of memory leakage prior to UE4 v4.16, where discarded widgets would simply refuse to go away under certain conditions.