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?
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.