Update UTextureRenderTarget2D from CPU data
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: https://wiki.unrealengine.com/Dynamic_Textures . However, doing this crashes the engine inside the RHIUpdateTextureRegions call...
Currently, my actor has a property like that:
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
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?
asked Jul 12 '18 at 11:46 AM in Rendering
Update: The approach of using practically the same code as in the UpdateTextureRegions() method works fine for Render Targets as well. It turns out that the whole problem was just a stupid copy-paste mistake: When updating the code from UpdateTextureRegions to use Render Targets, I simply forgot to change the type
answered Nov 21 '18 at 05:41 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here