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 :
#pragma once
#include "GameFramework/Actor.h"
#include "TestTarget.generated.h"
UCLASS()
class ATestTarget : public AActor
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION()
virtual void OnReceiveUpdate(class UCanvas* Canvas, int32 Width, int32 Height);
UPROPERTY(BlueprintReadOnly, Category = TestTarget)
class UCanvasRenderTarget2D* CanvasTarget;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = TestTarget)
UTexture* TestTile;
};
And cpp file :
#include "MyFlightSim.h" // Placeholder game name
#include "TestTarget.h"
#include "Engine/CanvasRenderTarget2D.h"
ATestTarget::ATestTarget(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
CanvasTarget = UCanvasRenderTarget2D::CreateCanvasRenderTarget2D(UCanvasRenderTarget2D::StaticClass(), 1024, 1024);
CanvasTarget->OnCanvasRenderTargetUpdate.AddDynamic(this, &ATestTarget::OnReceiveUpdate);
CanvasTarget->ClearColor = FLinearColor::Black;
}
void ATestTarget::OnReceiveUpdate(class UCanvas* Canvas, int32 Width, int32 Height)
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("TestTarget Received Update!"));
Canvas->SetDrawColor(0, 255, 0);
Canvas->DrawTile(TestTile, 0, 0, Width, Height, 0, 0, TestTile->GetSurfaceWidth(), TestTile->GetSurfaceHeight());
}
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!
Please help!