I am looking for a way to update a UTextureRenderTarget with content from the CPU.
Since its Resource member is a standard FTextureResource, I thought I would be able to update this simply by using UpdateTextureRegions the same way it is possible with normal UTexture2D instances, as demonstrated here: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums . However, doing this crashes the engine inside the RHIUpdateTextureRegions call…
Currently, my actor has a property like that:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UTextureRenderTarget2D* RTVideoTexture;
I created a RenderTarget2D asset in the editor and assigned it to this property of my actor instance through the editor.
In my actor, when I have new image data, I just use the UpdateTextureRegions from the above link to update the texture (modified so the function takes an FTextureResource). This works perfectly when “just” using UTexture2D instead of UTextureRenderTarget2D… I made sure the Render Target has the right size and pixel format in the editor, yet it still keeps crashing. I also tried something along the lines of
if (!RTVideoTexture) {
RTVideoTexture = NewObject<UTextureRenderTarget2D>();
}
RTVideoTexture->InitCustomFormat(VideoSize.X, VideoSize.Y, EPixelFormat::PF_B8G8R8A8, true);
RTVideoTexture->UpdateResource();
RTVideoTexture->UpdateResourceImmediate(false);
before updating/using the texture, still unsuccessfully…
Background:
I want to be able to define the texture that gets written to through the editor, as this texture gets used by several other actors/materials. If I would create a UTexture2D dynamically, this would require complicated blueprint/c++ setups to “publish” this dynamic texture to all the actors that use it. Using a RenderTarget asset would allow me to simply assign the RT asset to all objects in the editor, with no further blueprint magic…
Is there any way to do this?