How to declare multi-dimensional arrays?

I am going through a program in traditional C and it involves 2-dimensional arrays and a 4-dimensional integer array. I want to know how I can declare and initialize such arrays in Unreal C++.

Hey Sidbadass96-

There is no way to declare a mutli-dimensional array as is done in traditional programming (with the ArrayName[x][y] syntax). What you can do instead is create a struct that has an array property and then create an array of that struct. This will give you an array where each element is an array of the type defined in your struct. Let me know if you have any issues in setting this up.

Cheers

Doug Wilson

So for the four dimensional array, I should create the struct with an array property, then make an array of that struct (let that be a for reading convenience). Following this, can I make a struct with a as a property and then make an array of this struct (let this be b). So b becomes my 4-dimensional array. I hope my theory here is right? Also, will it work in reality? I have worked with UE4 blueprints and have sufficient programming experience, but am relatively new to Unreal C++, so please bear with me.

Each Struct array would be a single dimension of your multi-dimension array. For instance:

  • FStructA contains ArrayA which is an array of floats
  • FStructB contains ArrayB which is an array of ArrayA. This makes ArrayB a two-D float array
  • FStructC contains ArrayC which is an array of ArrayB. This makes ArrayC a three-D float array.

This process continues for each struct with an array of another struct. Having an array in your class of one of your previous structs also adds a level to the array dimensions.