The program crashes with an error message saying I am referencing an element of TArray with an invalid index. However, in my thought, this shouldn’t have happened because I am using only index 0, and the array at least has one element after its construction, and there is no logic that removes any element from it. The entire array seemed to be invalidated somehow.
UE4 uses garbage collection to manage memories safely. If the garbage collector detects a certain memory block that is not referenced by any pointers or handles, it releases the block, thinking the block is not needed anymore. What UPROPERTY() does is it tells to the garbage collector that it is still being used by this pointer or data structure. If this keyword is not presented in front of a referencing variable, then the garbage collector will naively release the memory block pointed by it, failing to detect its reference.
You should put UPROPERTY() in front of all the referencing variables to UObject/UStruct (and maybe UEnum, too?) them.