Could I get some help with CanvasRenderTarget2D?
Hi all! Just got the new preview code for 4.2 and got it compiled to try the new UCanvasRenderTarget2D. But I can't make it work.
My class' header :
And cpp file :
But the message is never shown! I inherit from this Actor in Blueprint with a root StaticMesh component (Cube Shape) with a simple instance from a material which has a single Texture2D parameter. In the Blueprint's construction graph, I assign to this parameter the property CanvasTarget. The ClearColor is not even updated!
I found a way to make it work, thanks to @Solid-Snake! Here is my Actor's C++ code for future reference.
To make it work, create a material with a named Texture2DParameter, assign it to an Actor Blueprint subclassing this class, adjust the defaults (surface size and parameter name). In the Construction Script, create a DynamicMaterialInstance and assign it to the property MaterialInstance.
I might be doing a Wiki page on this later. Thanks, awesome community!
answered May 18 '14 at 12:47 PM
Here is a minimum test case example that I quickly whipped up to test.
If you wish to copy this code into your project, make sure to add RenderCore to PrivateDependencyModuleNames array in your project's build configuration. ClearColor is also only an inherited variable from Render Targets and are not used in Canvas Render Target.
I get the feeling that it may be due to the mixture of Blueprints and C++ causing the problems as I only tested either a full Blueprint method or a full C++ method. However, I can't imagine that it would cause too many issues if the order of operations is done correctly.
Lastly remember when you debug things to ensure you are running in Debug Editor. Debugging in Development Editor usually leads to Visual Studio reporting strange values for variables.
Hopefully this code examples helps you to solve the problem on your end.
You should not be using the Actor's C++ constructor to create the canvas render target.
Try overriding AActor::BeginPlay() and putting it in there instead.
answered May 16 '14 at 11:23 PM
Hmm, I'm looking at your code and what is it that calls UCanvasRenderTarget2D::UpdateResource()? I also assume that TestTile is also valid?
I haven't yet synched with 4.2 preview yet, but I'll check it out when it has been released. However, when I was developing this feature it was working for me for both C++ and Blueprints.
answered May 17 '14 at 05:54 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here