Casting/Converting FRHITexture to UTexture

Hey guys,

kinda simple question: I have a pointer to a FRHITexture coming from a compute shader, which generates this texture every frame. I’d now like to somehow show it in the editor / set it as a TextureParameterValue in another material I’m using. But when I typecast it from FRHITexture2D* to UTexture2D*, the engine crashes when it wants to access the Texture. How should I do it?

Thanks a lot! :slight_smile:

bump bump bump

didnt get a solution yet, but this might be helpful: graphics - How to read data from a UTexture2D in C++ - Stack Overflow

You can’t, FRHITexture and UTexture2D are completely different types of object. RHITexture isn’t even a UObject.

Traditionally the UTexture2D is responsible for creating and then storing a reference to it’s RHI resource - that relationship is one-way.

You’ll probably have to fudge this a bit. The best way would be creating a UTexture2D* object, then passing it’s FRHIResource to your compute shader. Alternatively, you could try creating a new UTexture2D object, and instead of creating the resource, you’ll have to find a way to ‘Set’ the resource to your newly created FRHITexture.

You may have to modify engine source to do that and I have no idea if it’s possible and you’ll probably have to fight some threading issues between render/game thread too.

this link might be helpful: FTexture2DRHIRef clarification - Unreal Engine Forums

Are we really supposed to modify engine source to make UTexture2D’s from FRHIResource?

Is there no native engine method to do this?
Digging into source it seems they just Create Resources but never let you set an existing one.