TArray::Num
#include "Containers/Array.h"
Access: public
Specifiers: const
Description
Returns the number of elements currently in the array. Does not include any reserved but unused capacity.
Signature
UE_FORCEINLINE_HINT SizeType Num() const Return Type
int32 Caveats & Gotchas
- • Returns int32 (SizeType), not size_t. Comparisons with size_t values (e.g. from STL containers) may produce signed/unsigned mismatch warnings.
- • Use IsEmpty() rather than Num() == 0 for clarity. Both are O(1).
- • Num() reflects the logical size, not the allocated capacity. Use GetSlack() to see how many elements can be added before reallocation.
Example
Loop with index and bounds-guard C++
// Iterate with index
for (int32 i = 0; i < MyArray.Num(); ++i)
{
ProcessItem(MyArray[i]);
}
// Guard before accessing last element
if (MyArray.Num() > 0)
{
AActor* Last = MyArray[MyArray.Num() - 1];
} See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?