RealDocs

TArray::RangeCheck

function Core Since 4.0
#include "Containers/Array.h"
Access: protected Specifiers: inline

Description

Validates that an index is within the array bounds, triggering a checkf assertion on failure. Only active when the allocator's RequireRangeCheck policy is true; allocators like TInlineAllocator with NoRangeCheck disable this at compile time.

Caveats & Gotchas

  • This is a protected internal method called by operator[], Last(), Pop(), and other accessors — you almost never call it directly. Use IsValidIndex() for conditional checks that should not crash.
  • The check is a compile-time no-op when AllocatorType::RequireRangeCheck is false (e.g. with stack allocators configured for maximum performance). Do not rely on it firing in all configurations.
  • A two-parameter overload exists — RangeCheck(Index, Count) — that validates an entire subrange; use it when validating slice operations.

Signature

UE_FORCEINLINE_HINT void RangeCheck(SizeType Index) const

Parameters

Name Type Description Default
Index SizeType Index to validate against the array bounds.

Return Type

void

Example

Using IsValidIndex instead of RangeCheck for safe conditional access C++
TArray<int32> MyArray = {10, 20, 30};
int32 QueryIndex = 5;
if (MyArray.IsValidIndex(QueryIndex))
{
    // Safe — use operator[] which calls RangeCheck internally
    int32 Val = MyArray[QueryIndex];
}

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.