A list vs TArray

So I need to have a list of buffs(UObject pointers). Each Tick I update each of the buffs, and if it expired, I need to delete it.
Now, my question is, is there a good list to use vs TArrays ? TDoubleLinkedList ? (It would be enough linked list in just one direction, but the other Tlists in documentation seems to lack a lot of functionality). Removing an element in array is a pain, and I think there should be performance issues removing elements from it.

So what should I use ? And someone knows how would look the removal of elements from a List ?
Thanks.

TArray isn’t too bad. There are better ways of removing from TArrays than others though. What you probably want to do is something like this.

TArray<UBuff*> buffs;
buffs.RemoveAllSwap([&buffs](UBuff* Val){ return Val.TimeLeft <= 0.0f });

I wouldn’t worry too much about this until it actually becomes a bottleneck, and if it does I’d consider looking at solutions that fix the specific part of the problem that’s the bottleneck. Premature optimization is the root of all evil etc.

Good answer ! Really simple way to do this, but I just realised , in this case why do you even need buffs in the labda expression ? :slight_smile:

Oh, you’re right, you totally don’t. I copied it from another piece of my own code where I was passing in something else that was actually necessary.