Tutorial BP Single Class Multidimensional Array

Hi here’s something that I think, that it could be useful for someone:
Base Class:
image
Variables:
image

image

//I’m using Actor (cause I need some functionality), but it can be simplified using just UObject
Initialize using this function “Setup”:

Make functions to use your multidimensional array:
image

image

Usage:
Initialize:

Get Element from array:

1 Like

Thank you very much. :slight_smile:

1 Like

If you need to make a multi-dimensional array, structs of arrays can work too.

1 Like

More simple yes, but less functionality and when you modify something in the structure, it has the risk of corrupting, structures are very unstable.

I’ve made some small changes, this new version will allow more things:
Base Class:
image
Variables:
image
image
image

//I’m using Actor (cause I need some functionality), but it can be simplified using just UObject

Initialize using this function “Setup”:
image




(I’ve used arrays instead of a map because maps dont respect order of input)
Setup Auxiliary Functions:
image



This is only for child classes:
image
Make functions to use your multidimensional array:
image
image

To loop through you multidimensional array create a macro library using its parent class:
image
Create Function in Macro:

On base class:


image
Multidimensional Array with int/float values:
Create child Class:
image
variables:
image
Make functions to use your multidimensional array:

image
image
(I like to create my own setters and getters)
image
image
To fill array with one value:
image

Usage:



Idk if this is what you’re trying to achieve, but if you’re trying to make a general-purpose multidimensional array, it can be done simply by converting it into a one-dimensional array:

The size of the array is the product of the resolution (size) of all axes (e.g. resX * resY for 2D, and resX * resY * resZ for 3D).
And here are the indexing functions for 2-dimensional & 3-dimensional arrays, which include both coordinate-to-index and index-to-coordinate:


Coordinate-to-index converts a multidimensional coordinate into a one-dimensional coordinate (i.e. the index in the one-dimensional array), and index-to-coordinate does the opposite.
This also allows you to convert between dimensions; e.g. to convert from 2D to 3D, do 2D->1D->3D.

1 Like

This is a solution for someone like who is not really good at math like me and want a self made multimensional array solution: But hey, your comment here could be useful for other people who has a better understanding of math. :slight_smile:

Sorry, should’ve posted an actual example.
The first image shows the utility functions, and the second image shows how to use them.
For your case, you only need the Setup & CoordToIndex functions; the IndexToCoord is an extra utility.

1 Like

What I’m trying to do and I’m sorry for not understanding you in the first comment, is to show a how to have a multi purpose multidimensional array, not just for numbers but anything else. :smiley:
Edit: maybe my naming scheme was not the best and i’m also sorry for that too.

Oh, I see what you mean. I guess I misunderstood what you were trying to do. Sorry for the confusion. :sweat_smile:

1 Like