RealDocs

UKismetMathLibrary::Convert2DTo1D

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

Description

Maps a 2D (X, Y) array coordinate to its equivalent flat index in a row-major 1D array of the given width — the inverse of Convert1DTo2D.

Caveats & Gotchas

  • Assumes row-major layout (Index2D.X varies fastest); mismatched storage order will produce the wrong flat index.
  • No bounds checking is performed — passing Index2D.X >= XSize still returns a computed integer rather than an error, and it won't round-trip correctly through Convert1DTo2D.
  • Useful for indexing into a TArray used as a flattened grid, since TArray itself has no native 2D indexing.

Signature

static int32 Convert2DTo1D(const FIntPoint& Index2D, int32 XSize)

Parameters

Name Type Description Default
Index2D const FIntPoint& The 2D (X, Y) coordinate to convert.
XSize int32 Width (X dimension) of the logical 2D array.

Return Type

int32

Example

Index into a flattened tile array from grid coordinates C++
FIntPoint TileCoord(7, 4);
int32 GridWidth = 10;
int32 FlatIndex = UKismetMathLibrary::Convert2DTo1D(TileCoord, GridWidth);
ATile* Tile = TileArray[FlatIndex];

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.