x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

 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?

Product Version: UE 4.19
Tags:
more ▼

asked Jul 12 '18 at 11:46 AM in Rendering

avatar image

TheHugeManatee
1 1 3

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first

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 FTexture2DResource to FTextureRenderTarget2DResource and since it was using old c-style casts it would not give me a proper exception there. Then you can use it just fine as described in other places for updating "normal" Texture2D objects. However, be aware that RenderTargets only support a subset of the available pixel formats.

more ▼

answered Nov 21 '18 at 05:41 PM

avatar image

TheHugeManatee
1 1 3

(comments are locked)
10|2000 characters needed characters left
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question