# How does the "Import Buffer as Texture 2D" node work?

**URL:** <https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568>\
**Category:** Blueprint\
**Tags:** buffer, image, video-texture, unreal-engine, import, Array, Rendering, question, Blueprint\
**Created:** [September 10, 2023, 11:46pm UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568 "2023-09-10T23:46:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_untextured](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@The\_untextured](https://forums.unrealengine.com/u/The_untextured)\
**Post date:** [September 10, 2023, 11:46pm UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568/1 "2023-09-10T23:46:53Z")

</div>

The title explains it. This is the node:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/7/9078e6b2429287f56206a61698506ccf99154f3b.png)

I can’t figure out how it works. I am using it to try and save and load a render target, but I just don’t know how this node works. As in: how do I structure the input buffer array?

Having used other rendering APIs in the past, such as SFML, I assumed it was RGBA RGBA RGBA… for as many pixels as there are, but apparently that just gives out an empty image. (invalid object reference)

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [September 11, 2023, 4:00am UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568/2 "2023-09-11T04:00:28Z")

</div>

i think the buffer is a byte array for what is " file like" data.  
in other words similar to a binary jpeg.

check the comment on " compress image" and " decompress image" [https://github.com/EpicGames/UnrealEngine/blob/a3cb3d8fdec1fc32f071ae7d22250f33f80b21c4/Engine/Source/Runtime/Engine/Public/ImageUtils.h#L130](https://github.com/EpicGames/UnrealEngine/blob/a3cb3d8fdec1fc32f071ae7d22250f33f80b21c4/Engine/Source/Runtime/Engine/Public/ImageUtils.h#L130)

i dont see an export equivalent for the import buffer as texture 2d  
i think you might get more luck using “ExportTexture2D” and " ImportFileAsTexture2D" (both manipulates a file directly and uses a filename).

---

<div class="post-metadata">

**Author:** ![The\_untextured](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@The\_untextured](https://forums.unrealengine.com/u/The_untextured)\
**Post date:** [September 11, 2023, 8:07am UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568/3 "2023-09-11T08:07:05Z")

</div>

The problem with using a file is that I would like to have all save data in one single file. I will have a look at the source code, otherwise, I have a slower, alternative method… But it’s quite slow…

---

<div class="post-metadata">

**Author:** ![The\_untextured](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@The\_untextured](https://forums.unrealengine.com/u/The_untextured)\
**Post date:** [September 11, 2023, 11:56am UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568/4 "2023-09-11T11:56:48Z")

</div>

Solved. What I am trying to do is save a render target to a save file and load it back in. The render target uses 8 bit RGB (24 bits per pixel) and will always be square. To save, I just use the “Read Render Target” node: it’s slow but it works. I save the output using a SaveGame object.

To load it back in, I created a C++ function which looks as follows:  
.h:

```cpp
[...]
	UFUNCTION(BlueprintCallable, Category = "Rendering")
	static TArray<uint8> getBufferFromColorArray(TArray<FColor> arr);
[...]

```

.cpp:

```cpp
#define add(num) working.Add(num)
#define addInt(num, size) working.Append(intToBytes(num, size))
TArray<uint8> UCPP_BPFuncLib::getBufferFromColorArray(TArray<FColor> arr)
{
	int size = sqrt(arr.Num());

	TArray<uint8> working;
	//header
	add(66);
	add(77);
	//size
	add(0);
	add(0);
	add(0);
	add(0);
	//app info
	add(0);
	add(0);
	add(0);
	add(0);
	//start address
	add(54);
	add(0);
	add(0);
	add(0);

	//BITMAPINFOHEADER
	//size of header
	add(40);
	add(0);
	add(0);
	add(0);
	//image size
	addInt(size, 4);
	addInt(size, 4);
	//color planes
	addInt(1, 2);
	//color depth
	addInt(24, 2);
	//compression
	addInt(0, 4);
	//dummy int
	addInt(0, 4);
	//resolution
	addInt(0, 4);
	addInt(0, 4);
	//colors in color pallette
	addInt(0, 4);
	//important colors
	addInt(0, 4);
	//image buffer
	size = arr.Num();
	for (int i = 0; i < size; i++) {
		add(arr[i].B);
		add(arr[i].G);
		add(arr[i].R);
	}
	//set real file size
	size = working.Num();
	auto tmp = intToBytes(size, size);
	for (int i = 0; i < 4; i++) {
		working[i + 2] = tmp[i];
	}
	return working;
}

```

This pretty much just turns the FColor buffer saved into a uint8 (byte) buffer array which can be used in the “Import Buffer as Texture 2D” node.

I then use this image as a parameter of a UI material (“Tex”) as such:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/c/60cbdd653a98fec90144d77876154e4f15b221b8.png)  
(The reason why the V component in the texture coordinate is flipped is due to how bitmaps are saved. Otherwise the image gets flipped.)  
I then copy the material to the render target and it’s done!

---

<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:** [October 11, 2023, 11:57am UTC](https://forums.unrealengine.com/t/how-does-the-import-buffer-as-texture-2d-node-work/1290568/5 "2023-10-11T11:57:23Z")

</div>

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