UViewport: viewport widget, how to make it transparent?

Hello,

I’m trying to render main world independently rendered 3D objects on player hud via UMG.

The code I wrote is correctly working. I can see the viewport over the main rendered scene and the actor I’m spawning in it, but background is fully black. I’d like to have a transparent background so I can just see 3D objects overlayed.

This is the code:

UWorld* World = PlayerController->GetWorld();
UObject* Outer = World->GetGameInstance() ? StaticCast<UObject*>(World->GetGameInstance()) : StaticCast<UObject*>(World);
UViewport* MiniMap = ConstructObject<UViewport>(UViewport::StaticClass(), Outer);

MiniMap->BackgroundColor = FLinearColor(0.0f, 0.0f, 0.0f, 0.0f);

CanvasPanel->AddChild(MiniMap);

MiniMap->Slot->SetDesiredPosition(FVector2D(60.0f, 280.0f));
MiniMap->Slot->SetDesiredSize(FVector2D(1000.0f, 1000.0f));

AVProjectile* test = Cast<AVProjectile>(MiniMap->Spawn(AVProjectile::StaticClass()));

test->SetActorLocation(FVector(0.0f, 100.0f, 0.0f));

Any luck on figuring this one out? I’m interested in doing this as well.

I’m currently using a SceneCapture2D with a RenderTexture to render the objects I want to be overlayed in a “black room”.

I then make a material with masked blend mode, connect the rendertexture output to base color and to opacity mask. Set the Opacity Mask Clip Value to an appropriate value, so that all black background will result transparent on the material.

At this point you can apply that material to an hud element or a UMG image widget.