If you have tried my previous tutorial, you might found some wired transform happened. The cube rendered should be static and stay at the origin point (0, 0, 0). Those wired transform could be reproduced by switch the View Mode to Reflection and then switch it back to Lit in any editor viewport.


As we all know (not), the ViewMode can be set by FEditorViewportClient::SetViewMode(EViewModeIndex InViewModeIndex). I just found it by searching text SetViewMode actually XD.

void FEditorViewportClient::SetViewMode(EViewModeIndex InViewModeIndex)
	// ...


The Invalidate() called here will invoke FViewport::Invalidate() using the FViewport instance it held.

void FViewport::Invalidate()

Then we will find the FViewport::InvalidateDisplay() is a pure virtual function. So lets find out where it dispatched to. Using the find usages of your IDE is helpful to do this job. After that, we should found FSceneViewport implemented it. Keeping to dig them out and I found the viewport set in graphics pipeline might be different to the actually view. The reason could be the viewport scaling I guess.


FIntRect ViewportSize = ViewInfo.ViewRect;

RHICmdList.SetViewport(static_cast<float>(ViewportSize.Min.X), static_cast<float>(ViewportSize.Min.Y), 0.0f, static_cast<float>(ViewportSize.Max.X), static_cast<float>(ViewportSize.Max.Y), 1.0f);

This should fix the transform error.