TArrayMyArray(5); int index = 3; if (MyArray.IsValidIndex(index)) { // Do something with MyArray[index] }
TArrayIn this example, we have a TArray of booleans with four elements. Then we try to access the element at index 4, which is an invalid index. In the following If-condition, we check if the index is invalid using IsValidIndex. If it's invalid, we expand the size of the array to index + 1 using SetNum. Package Library: TArray is part of UE4 (Unreal Engine 4) Core library.Flags = { true, false, false, true }; int index = 4; if (!Flags.IsValidIndex(index)) { Flags.SetNum(index + 1); }