trying to figure out an ammunition based system for my third person shooter game and figured multi dimensional array
would be the best way to go in terms of tracking ammunition count and ammo magazine clips.
however stumbled across a tutorial series Rama implemented in regarding a Flower struct getting wrapped in an array wrapped by another struct and so forth.
I was just wondering, is there a better means than that approach? or is that my best bet.
and again, this is more an emphasis on implementing and understanding multi dimensional arrays.
If you want it exposed as a UPROPERTY, then no it’s not supported (and it probably won’t ever be).
However there’s not really much need for it - since with some fairly straightforward accessor operations you can treat a 1D array as a multidimensional array anyway, and it’s considerably faster than using multi-dimensional arrays. Here’s an example from some code I used quite often.
/* Get the Index in a 1D array when treating it as 2D */
FORCEINLINE static int32 Get2DArray_Index(const int32 Column, const int32 Row, const int32 NumRows)
return Row + Column * NumRows;
/* Get the Column and Row from the Index of a 1D Array treated as 2D.*/
FORCEINLINE static void Get2DArray_ColumnAndRow(int32& OutColumn, int32& OutRow, const int32 NumRows, const int32 InIndex)
checkfSlow(NumRows > 0, TEXT("UST_SGStatics::Get2DArray_ColumnAndRow() - Divide By Zero!"));
checkfSlow(InIndex >= 0, TEXT("UST_SGStatics::Get2DArray_ColumnAndRow() - Invalid Index!"));
OutColumn = InIndex % NumRows;
OutRow = InIndex / NumRows;
Note that Arrays also have more complex and often costly replication, since the number of elements in the array is also sent, even if the array is empty.
I’m not strictly after exposing UPROPERTIES, that part doesn’t phase me, but is there any chance you can give me an example of using this snippet/ share me a link in reading up on what exactly this is…
essentially I would like to create something along the lines of this table if this makes sense:
so when I reload with a 5.56mm weapon, I want the reload function to point to either column 1 or 3 (orange cells) of a “multidimensional” array to reload the weapon with either of those clips and then remove it from the array.