RealDocs

UKismetMathLibrary::Convert1DTo2D

function Engine Blueprint Since unknown
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Maps a flat 1D array index to its equivalent (X, Y) coordinate in a row-major 2D array of the given width, e.g. for reading a flattened grid or tile map array.

Caveats & Gotchas

  • • Assumes row-major layout (X varies fastest); if your data is stored column-major, X and Y in the result will be swapped relative to your storage.
  • • No bounds checking is performed — passing an Index1D beyond XSize * YSize of your actual array still returns a computed FIntPoint, it just won't correspond to a valid element.
  • • XSize of 0 will divide by zero internally; guard against it if XSize is computed dynamically.

Signature

static FIntPoint Convert1DTo2D(int32 Index1D, int32 XSize)

Parameters

Name Type Description Default
Index1D int32 The flat array index to convert. —
XSize int32 Width (X dimension) of the logical 2D array. —

Return Type

FIntPoint

Example

Convert a flat tile array index to grid coordinates C++
int32 FlatIndex = 47;
int32 GridWidth = 10;
FIntPoint GridCoord = UKismetMathLibrary::Convert1DTo2D(FlatIndex, GridWidth);
// GridCoord = (7, 4)

Version History

Introduced in: unknown

Version Status Notes
5.6 stable —

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.