Hello guitou80,
as I understand your code, you probably want to use the 2-dimensional array to address every square on the screen? This is totally possible!
Let us start with the header file. You want to be making StaticCubesMatrix a UPROPERTY so that you can view and/or edit the property right in the editor and allow blueprints to read and even access it if you want to. To do so simply add UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Tetris”) directly above the array declaration; this will make your array show up and editable in the editor under the category specified and allow blueprints to read and modify its contents. If you only want the array to be visible in the editor replace EditAnywhere with VisibleAnywhere, and if you only want blueprints to read, replace BlueprintReadWrite with BlueprintReadOnly.
Something to node is that when you make your TArray a UPROPERTY its template argument must be an UCLASS, an USTRUCT, an UENUM, a special type, like FVector, or a primitive type such as a int32, float, or bool. So you must make your CubeStruct a USTRUCT. To do this, simply add USTRUCT(BlueprintType) directly above the declaration “struct CubeStruct”; ‘BlueprintType’ makes the struct a valid type for blueprints to reference. Also, you must rename the struct to “FCubeStruct” because of the naming convention used in Unreal software. Also, add GENERATED_BODY() right after the the first “{” parenthesis; this is required by the Unreal Header Tool.
Now, as we want a 2-dimensional array we might be tempted to write something like this: TArray<TArray<FCubeStruct>> StaticCubesMatrix. This seems fine but the Unreal Header Tool will complain about this stating that a tarray of tarrays is not allowed. Luckly, we can ‘trick’ the header tool by defining another USTRUCT which will look like this:
USTRUCT(BlueprintType)
struct FArrayPlaceholder
{
GENERATED_BODY()
TArray<FCubeStruct> Placeholder;
};
With this type, we declare StaticCubesMatrix as this: TArray StaticCubesMatrix. You just need to adjust your iteration code slightly now: in C++ arrays start at index 0 and the maximum index is its size - 1. So to iterate your matrix, you would use this code:
for(size_t i = 0; i < StaticCubesMatrix.Num(); ++i)
{
for(size_t j = 0; j < StaticCubesMatrix*.Placeholder.Num(); ++j)
{
/* Init a FCubeStruct named Data here */
StaticCubesMatrix*.Placeholder[j] = Data;
}
}
I hope I could help.