Search code examples
c++arraysunreal-engine4nullptr

Is it safe to access TArray at an invalid index?


I want to know if the following code would return nullptr reliably without any complications:

TArray<ASomeActor*> SomeActors;

ASomeActor* SomeActor = SomeActors[0];

return SomeActor;

Solution

  • No. According to documentation, that is not allowed:

    Passing an invalid index — less than 0 or greater than or equal to Num() — will cause a runtime error.