Slate viewport positioning not correct.

In the code below, I’m trying to draw some text in the lower-right corner using SCanvas, However the text appears in the middle of the viewport (see pic below). Changing position to have a value of (size*2) - textSize moves the text past the lower-right corne. Does the GameViewport or SCanvas have a scale transform set by default? Any suggestions for what I’m doing wrong?

		SAssignNew(Canvas, SCanvas);
		GEngine->GameViewport->AddViewportWidgetContent(
			Canvas.ToSharedRef()
		);
		FString message("Hello, World!");
		FText txt = FText::FromString(message);
		FVector2D size;
		GEngine->GameViewport->GetViewportSize(size);
 		GLog->Logf(TEXT("Size: %f %f"), size.X, size.Y);

		FVector2D textSize(320, 60);
		FVector2D position(size - textSize);
		Canvas->AddSlot()[
			SNew(SBorder)[
				SNew(STextBlock)
					.Text(txt)
					.Font(FSlateFontInfo(
						FPaths::EngineContentDir() / TEXT("Slate/Fonts/Roboto-Bold.ttf"),
						40))
			]
		]
			.Position(position)
			.Size(textSize);

Edit: Fixed image so that it shows inline.

Use an SConstraintCanvas and add this to your slot.

.Anchors(FAnchors(0.5f, 1.0f))
.Offset(FMargin(0.f, 0.f))
.Alignment(FVector2D(1.f, 1.f))

Thanks for the response, but I’m looking for an explanation of why SCanvas isn’t putting the child widget where I think it should go. The example is just to show what I’m seeing so hopefully someone can explain why the text widget isn’t going to the position I’m passing to the slot.

Yeah, that sounds like the same problem. No response, though :frowning:

Thanks to Nick Darnell and JonathanADaley’s answer in this question, I was able to fix it. I was not taking into account the DPI scaling. I added JonathanADaley’s GetUMG_DPI_Scale function and replaced line 12 in my code with:

		float dpiScaling = GetUMG_DPI_Scale();
		FVector2D position((size / dpiScaling) - textSize);

The text now appears in the correct place.

Thanks. That’s what I was missing. Posted the updated code below…

Can’t test it at the moment, but I noticed this related question.

DPI scale. The canvas isn’t in the same space as the viewport, since its space is a function of the DPI Scale curve based on the viewport size.