RealDocs

TSet

struct Core Since 4.0
#include "Containers/Set.h"

Description

An unordered container of unique elements backed by a hash set. Average-case Add/Contains/Remove are O(1). Use instead of TArray when you need fast membership tests and don't care about order.

Signature

template<typename ElementType, typename KeyFuncs, typename Allocator> class TSet

Caveats & Gotchas

  • Elements must be hashable — same requirement as TMap keys.
  • No stable iteration order. If order matters, use TArray instead.
  • Adding a duplicate element is a no-op — the set silently ignores it.
  • Cannot be used as a UPROPERTY without specific type support.

Example

Track visited actors C++
TSet<AActor*> VisitedActors;
VisitedActors.Add(SomeActor);

if (!VisitedActors.Contains(SomeActor))
{
    // first visit
    VisitedActors.Add(SomeActor);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.