SplitScript reference / Set<T>

Set<T>

type constructor

Set<T where Equatable>

Stores a growable collection of unique values for one script instance.

A set keeps its allocation and contents across ticks. Mutating operations update the same set value, so a global set can track visited checkpoints without rebuilding a collection on every update. Equality compares complete element values independently of insertion order. Sets can themselves be set elements or map keys, including recursively nested collections.

In Unity schemas, sets describe managed hash sets. Elements must support ManagedReadable and local equality. Reads recursively create owned, deeply immutable values and share their root's budgets. Distinct game elements that decode to equal local values make the whole read fail. Recursive duplicate comparisons share the read's work budget; exhaustion fails the read and leaves the previous state value intact.

Examples

Track visited rooms

let visited = Set.new<String>()
visited.insert("Atrium")

Methods

MemberDescriptionAvailable through
clearRemoves every stored value while retaining the set itself.
containsReports whether an equal value is present.
insertInserts a value if it is not already present.
isEmptyReports whether the set contains no values.
iteratorCreates an independent cursor over this set.
lengthReturns the number of stored values.
newCreates an empty set.
removeRemoves an equal value if it is present.