Converting an array of pixel values to a texture.

Id like to update a texture in real-time, with pixel values from an array.

Im very new to C++ programming, so help with this would be greatly appreciated.

I recently went through this, use CreateTransient…

UTexture2D * texture = UTexture2D::CreateTransient( width, height, PF_B8G8R8A8 );
void * TextureData = texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy( TextureData, data, 4*width*height );

Before that I was trying to use FImageUtils::CreateTexture2D, but it didn’t work when I tried it with a packaged build.

Thanks so much @nullterm
Could anyone tell me how I return a reference to the texture 2D so I can access it in blueprint?
Sorry for my noobiness

Well for anyone wondering, I got a blueprint reference like this.

void ProceduralTextureWriter::WriteTexture(UTexture2D*& texture)

texture = UTexture2D::CreateTransient(64, 64, PF_B8G8R8A8);

I dont know if thats the right way, but it works.

Also I should point out, this method **nullterm **provided is somewhat slow. The Memcpy part of the code is not cheap, its not suitable for real-time unless you are using low resolution textures. If anyone knows a faster method, please do say.