# How to Make a Texture 2D Array during Runtime in c++? Or Texture Atlas

**URL:** <https://forums.unrealengine.com/t/how-to-make-a-texture-2d-array-during-runtime-in-c-or-texture-atlas/2059221>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [October 8, 2024, 7:56pm UTC](https://forums.unrealengine.com/t/how-to-make-a-texture-2d-array-during-runtime-in-c-or-texture-atlas/2059221 "2024-10-08T19:56:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FiscalFlipper1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FiscalFlipper1](https://forums.unrealengine.com/u/FiscalFlipper1)\
**Post date:** [October 8, 2024, 7:56pm UTC](https://forums.unrealengine.com/t/how-to-make-a-texture-2d-array-during-runtime-in-c-or-texture-atlas/2059221/1 "2024-10-08T19:56:56Z")

</div>

Hello everyone, I’m trying to combine several individual textures into one, either with a Texture 2D Array or a Texture 2D, but I can’t find the correct way to do it.

I wrote this code I found where they copy the data from each of the individual textures to a Texture 2D Array, but the final image is just random pixels.

I searched for more information about these Unreal Engine classes, but there is no clear documentation. I did the same thing in Godot, and it’s easier to create a Texture Atlas.

Code:

```auto
void SetVoxelTextureArray(TArray<UTexture2D*>& ArrayTextures){

	// INIT TEXTURE ARRAY
	VoxelTextureArray = UTexture2DArray::CreateTransient(16, 16, ArrayTextures.Num() + 1);
	VoxelTextureArray->UpdateResource();

	// GET THE DATA OF THE TEXTURE
	void* TextureData = VoxelTextureArray->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_WRITE);

	// DEFINE THE SIZE OF THE TEXTURES 16X16 PIXELS
	int64 MemoryOffset = 0;
	uint32 TextureSize = 16 * 16 * 4;

	for (int32 i = 0; i < ArrayTextures.Num(); i++){
		// ASSIGN THE MEMORY TO THE VARIABLE SLICE DATA
		void* SliceData = (uint8*)TextureData + MemoryOffset;

		// GET THE DATA FOR EACH INDIVIDUAL TEXTURE
		const void* SourceData = ArrayTextures[i]->GetPlatformData()->Mips[0].BulkData.LockReadOnly();
		
		// COPY THE DATA
		FMemory::Memcpy(SliceData, SourceData, TextureSize);

		ArrayTextures[i]->GetPlatformData()->Mips[0].BulkData.Unlock();

		// INCREMENTE THE MEMORY OFFSET TO THE SIZE OF EACH TEXTURE
		MemoryOffset += TextureSize;
	}

	VoxelTextureArray->GetPlatformData()->Mips[0].BulkData.Unlock();

	VoxelTextureArray ->UpdateResource();

}

```

 ![UnrealWeirTexture2DArray](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/6/1/d611100f93b36c16cbef4cd265de03a752cf5568.png)

---

<div class="post-metadata">

**Author:** ![FiscalFlipper1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FiscalFlipper1](https://forums.unrealengine.com/u/FiscalFlipper1)\
**Post date:** [October 8, 2024, 9:36pm UTC](https://forums.unrealengine.com/t/how-to-make-a-texture-2d-array-during-runtime-in-c-or-texture-atlas/2059221/2 "2024-10-08T21:36:35Z")

</div>

For anyone with the same problem, i downloaded the [**Rama’s Extra Blueprint Nodes for UE5**](https://forums.unrealengine.com/t/ramas-extra-blueprint-nodes-for-ue5-no-c-required/231476)]

And this is my code in Blueprints, the only issue is that all the textures are 1 unit size in Y-axis.

 ![UnrealSolution](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/9/bb9f761d438444e59ecb3942892644f4f0726147.png)

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 7, 2024, 9:36pm UTC](https://forums.unrealengine.com/t/how-to-make-a-texture-2d-array-during-runtime-in-c-or-texture-atlas/2059221/3 "2024-11-07T21:36:59Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
