Hi am trying to draw text as a parameter of my Material using the delegate UCanvasRenderTarget2D, but it’s always drawing white.
Here is my material:
And here is my code:
void ALetterCube::BeginPlay()
{
Super::BeginPlay();
UWorld* world = GetWorld();
if(world){
CanvasRenderTarget = Cast<UCanvasRenderTarget2D>(UCanvasRenderTarget2D::CreateCanvasRenderTarget2D(world, UCanvasRenderTarget2D::StaticClass(), 1024, 1024));
CanvasRenderTarget->OnCanvasRenderTargetUpdate.AddDynamic(this, &ALetterCube::DrawToCanvasRenderTarget);
UMaterialInstanceDynamic* MaterialInstance = UMaterialInstanceDynamic::Create(LetterMaterial, CubeMesh);
MaterialInstance->SetTextureParameterValue(FName("LetterInput"), CanvasRenderTarget);
CubeMesh->SetMaterial(0, MaterialInstance);
CubeMesh->SetMaterial(1, MaterialInstance);
CubeMesh->SetMaterial(2, MaterialInstance);
CubeMesh->SetMaterial(3, MaterialInstance);
CubeMesh->SetMaterial(4, MaterialInstance);
CubeMesh->SetMaterial(5, MaterialInstance);
CanvasRenderTarget->UpdateResource();
}
}
void ALetterCube::DrawToCanvasRenderTarget(UCanvas* Canvas, int32 Width, int32 Height)
{
//Drawing code with UCanvas goes here...
Canvas->SetDrawColor(FColor::Black);
Canvas->DrawText(MyFont, FText::FromString(FString::Printf(TEXT("C"))), 0, 0);
}
If I change the color of the material to black (in the Param) I can see the letter C in white.
Any idea why it’s not working? Thanks alot!