Alexa.Ki
(Alendromeda.ki)
1
I want to make an array of struct like in this working blueprint script.
What I am doing wrong in my code?
void AMyGameMode::RandomRow(ST_MyStruct& Item)
{
TArray<ST_MyStruct> Arr[100];
TArray<ST_MyStruct> &GetByRef = Arr;
GetByRef = Arr[FMath::RandRange(0, Arr.Num() - 1)];
FCustomThunkTemplates::Array_Shuffle(Arr);
Item = GetByRef;
}
Error on compile time:
GetByRef’: ‘TArray<ST_MyStruct,FDefaultAllocator> &’ differs in levels of indirection from 'ST_MyStruct
1 Like
c0r37py
(c0r37py::)
2
heya Alexa! try this
TArray<ST_MyStruct> Arr[100];
ST_MyStruct &GetByRef = Arr[FMath::RandRange(0, Arr.Num() - 1)];
FCustomThunkTemplates::Array_Shuffle(Arr);
Item = GetByRef;
Hope it Helps
cheers!
2 Likes
Alexa.Ki
(Alendromeda.ki)
3
Now I got the error Array index out of bounds: 0 from an array of size 0 UE4Editor-Win64-DebugGame.exe has triggered a breakpoint.

c0r37py
(c0r37py::)
4
your array is empty, you are trying to randomize an empty array. Set the maximum range before you randomize it.
Arr.SetNum(100);
hope it helps
cheers!
2 Likes
Alexa.Ki
(Alendromeda.ki)
5
Thank You very very much for solving this issue, appreciated very much 