How to write to UCanvasRenderTarget2D in C++
I have a pretty simple setup for a RenderCanvasTarget2D in Blueprint which I am trying to recreate in C++, but it's not working for some reason.
Here is the BP version:
In a BP derived from RenderCanvasTarget2D, this is the 'Event Receive Update' delegate function:
And then in a BP actor, I have this in BeginPlay:
This successfully creates a CanvasRenderTarget2D of 128x128 pixels, writes a diagonal line across it, and saves it to the hard disk. All working perfectly.
In the C++ version, I am doing everything in a single actor called 'HDRWriter'. Here is the full relevant code:
So I run SetupCanvas to create the CanvasRenderTarget2D and bind a function (WhenCanvasUpdated) to the delegate OnCanvasRenderTargetUpdate. When I then call CallUpdate() it calls UpdateResource() on the CanvasRenderTarget.
When the function WhenCanvasUpdated() is then run, it should draw a line and save the file to the hard disk, as with the Blueprint version.
However, a file is indeed saved, but it is totally black - no line is drawn. I feel like I'm missing some important connection between the RenderCanvasTarget and the UCanvas that is passed in the delegate function, but I can't see how they should be connected.
I tried nativizing the BP into C++ code, but found it to be completely illegible.
Does anyone know what I'm doing wrong here?
asked Mar 12 '18 at 06:03 PM in C++ Programming
Is there a reason you're using OnCanvasRenderTargetUpdate rather than manually controlling the drawing yourself? I'm using a CanvasRenderTarget2D successfully in C++, but my flow looks like:
Granted, I'm not using ExportRenderTarget, but rather generating a dynamic material instance with the contents, but still, it's properly updating the canvas.
answered May 09 '19 at 01:39 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here