Currently a UTexture2DDynamic can’t be used in a plugin because it has no methods exposed with the ENGINE_API so trying to initialize it with Init() causing link errors.
I could use FSlateTexture2DRHIRef for a dynamic texture but I don’t think I can plug that into a MID as a texture parameter.
What is the right way to create a dynamic texture, lock and write to it every frame, and plug it into a MID. Is UTexture2D::CreateTransient() a dynamic texture?
I just use a FTexture2DRHIRef and create it using RHICreateTexture2D passing it TexCreate_Dynamic if you need to update it every frame
Hi there, this doesn’t address the real issue which is that an FTexture2DHIRef can’t be passed to a UMaterialInstanceDynamic to replace a texture input.
Sorry, create texture using CreateTransient in UTexture2D. Then to lock and write to it use
FTexture2DMipMap& Mip = [Texture]->PlatformData->Mips[Level];
void* Data = Mip.BulkData.Lock( LOCK_READ_WRITE );
FMemory::Memcpy( Data, NewData, DataSize );
Then pass the UTexture2D to your MID to show.
OK for this method to work you also have to call UpdateResource() on the texture. This destroys the underlying HRI texture resource and recreates it from scratch. This is very costly in terms of performance, definitely not suitable for the application in my original question which is doing this every frame.
I created a wikipage containing multiple solutions to this problem, the most performant one is first and lets you update subregions of the texture using ENQUEUE_UNIQUE_RENDER_COMMAND
After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
Reading time: 1 mins 🕑
Likes: 14 ❤
I would recommend that you post your solution regardless. Both cases will have their uses
Edit: you posted too quickly for me. You’ll need to look into a method that maps the underlying resource then.