How to add a viewport to custom editor window?

You’ll need two classes derived from these:

  • SEditorViewport - A slate widget to host your viewport client
  • FEditorViewportClient - A viewport client to handle the input and rendering

Since you already have an editor window, you probably have tabs already in place.
Slate widgets would go in these tabs, one of which would be your 3D viewport.
So, you’ll need to first create a slate widget for your 3D viewport by deriving from SEditorViewport

Override the SEditorViewport::MakeEditorViewportClient() function and provide your own “ViewportClient” implementation. You do this by subclassing from FEditorViewportClient

There is also a class called FPreviewScene. You can create this in the SEditorViewport::Construct function.
This is an easy way to manage the actors in your preview scene (it will have its own world)

Search SEditorViewport and FEditorViewportClient in the engine’s code from github for examples
https://github.com/EpicGames/UnrealEngine

1 Like