I am trying to display a button on the PC Side of Spectator Screen in a VR game. Everything else is working fine, but the mouse interaction doesn’t seem to work… Or maybe it’s that the mouse coordinates are correct?
Here is my code:
SpectatorScreenInstance = MainVertigoController->CreateSlateSpectatorWidget(SpectatorScreenClass);
SpectatorScreenInstance->ForceLayoutPrepass();
TSharedRef<SWidget> SlateSpectatorWidget = SpectatorScreenInstance->TakeWidget();
FVector2D RenderSize;
SlateSpectatorWidget->SlatePrepass(1.f);
FVector2D DesiredSize = SlateSpectatorWidget->GetDesiredSize();
RenderSize.X = FMath::RoundToInt(DesiredSize.X);
RenderSize.Y = FMath::RoundToInt(DesiredSize.Y);
TSharedPtr<FWidgetRenderer> SpectatorWidgetRenderer;
if (!SpectatorWidgetRenderer.IsValid()){
SpectatorWidgetRenderer = MakeShareable(new FWidgetRenderer(true));
}
UTextureRenderTarget2D* SpectatorWidgetRenderTarget = SpectatorWidgetRenderer->DrawWidget(SlateSpectatorWidget, RenderSize);
SpectatorWidgetRenderTarget->ClearColor = FColor::Black;
UHeadMountedDisplayFunctionLibrary::SetSpectatorScreenMode(ESpectatorScreenMode::TexturePlusEye);
UHeadMountedDisplayFunctionLibrary::SetSpectatorScreenTexture(SpectatorWidgetRenderTarget);
FVector2D EyeRectMin = FVector2D(0.0f, 0.0f);
FVector2D EyeRectMax = FVector2D(0.8f, 1.0f);
double TextureMinX = UKismetMathLibrary::MapRangeClamped(500, 1920, 0, 0, 1);
FVector2D TextureRectMin = FVector2D(TextureMinX, 0.0f);
FVector2D TextureRectMax = FVector2D(1.f, 1.f);
UHeadMountedDisplayFunctionLibrary::SetSpectatorScreenModeTexturePlusEyeLayout(EyeRectMin, EyeRectMax, TextureRectMin, TextureRectMax, true, false, false);
UVertigoSpectatorScreen* AVertigoController::CreateSlateSpectatorWidget(TSubclassOf<UVertigoSpectatorScreen> InSpectatorWidgetClass)
{
return CreateWidget<UVertigoSpectatorScreen>(this, InSpectatorWidgetClass.Get());
}