# How to copy an Array saved as TUniquePtr?

**URL:** <https://forums.unrealengine.com/t/how-to-copy-an-array-saved-as-tuniqueptr/729825>\
**Category:** C++\
**Tags:** unreal-engine, pointer, CPP, question\
**Created:** [December 16, 2022, 1:41pm UTC](https://forums.unrealengine.com/t/how-to-copy-an-array-saved-as-tuniqueptr/729825 "2022-12-16T13:41:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schrello](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schrello](https://forums.unrealengine.com/u/Schrello)\
**Post date:** [December 16, 2022, 1:41pm UTC](https://forums.unrealengine.com/t/how-to-copy-an-array-saved-as-tuniqueptr/729825/1 "2022-12-16T13:41:43Z")

</div>

Hey,

I am using `TUniquePtr<uint8[]> PixelBuffer;` to store pixel data of a texture as an array. Like [iUltimateLP](https://gist.github.com/iUltimateLP/baca7aee4b28585b5fd2d0d46b541d95) does it in his code.

The creation and drawing of the texture is working so far. (as shown in the picture below)  
 ![origin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/e/7beec03704814313cdce224a7bc6cd2a44d0a9f5.png)

Now I am trying to create a copy of that array using a for loop. (I am using a for loop because I want to extract just parts of the texture later on. But just for demonstration I copy the array completly in this example.)

```auto
SIZE_T PartBufferSize = WorldTextureWidth * WorldTextureHeight * DYNAMIC_TEXTURE_BYTES_PER_PIXEL;
	TUniquePtr<uint8[]> PartPixelBuffer = MakeUnique<uint8[]>(PartBufferSize);
	
	for (int i = 0; i < WorldTextureHeight *WorldTextureWidth * DYNAMIC_TEXTURE_BYTES_PER_PIXEL; i++) {

		PartPixelBuffer[i] = PixelBuffer[i];
	}

```

The pixels after copying are mixed up and the picture is different every time I execute this code. (as shown on the picture below)

 ![Unbenannt-1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/0/310ebd846e056c98096efb70bdb72ecbd3a0adb7.png)

What am I doing wrong?
