UKismetArrayLibrary::Array_AddUnique
#include "Kismet/KismetArrayLibrary.h"
Access: public
Specifiers: staticBlueprintCallableCustomThunk
Description
Adds an item to the array only if an equal item isn't already present, returning the index of the item.
Caveats & Gotchas
- • Returns INDEX_NONE (-1) if the item is already present in the array, per the header comment — it does not return the existing item's index in that case, which can surprise callers expecting 'find or add' semantics.
- • Equality is determined by the element type's operator== via reflection, so for struct or object element types this can be more expensive per-call than the equivalent native TArray::AddUnique.
- • Same wildcard/CustomThunk caveats as Array_Add apply — the declared int32 signature is a placeholder for any array element type.
Signature
static int32 Array_AddUnique(UPARAM(ref) TArray<int32>& TargetArray, const int32& NewItem); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| TargetArray | UPARAM(ref) TArray<int32>& | The array to add the item to. Passed by reference and mutated in place. | — |
| NewItem | const int32& | The item to add to the array if not already present. | — |
Return Type
int32 Example
Add an item only if not already present C++
TArray<int32> Values = {1, 2, 3};
int32 Index = UKismetArrayLibrary::Array_AddUnique(Values, 2); // Index == -1, Values unchanged Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?