- Open your editor module's header file (Chapter_10Editor.h) and add the following code:
class FChapter_10EditorModule: public IModuleInterface
{
virtual void StartupModule() override;
virtual void ShutdownModule() override;
TArray< TSharedPtr<IAssetTypeActions> > CreatedAssetTypeActions;
TSharedPtr<FExtender> ToolbarExtender;
TSharedPtr<const FExtensionBase> Extension;
IConsoleCommand* DisplayTestCommand;
IConsoleCommand* DisplayUserSpecifiedWindow;
- Add the following code within the implementation of StartupModule:
DisplayTestCommand = IConsoleManager::Get().RegisterConsoleCommand(TEXT("DisplayTestCommandWindow"), TEXT("test"), FConsoleCommandDelegate::CreateRaw(this, &FChapter_10EditorModule::DisplayWindow, FString(TEXT("Test Command Window"))), ECVF_Default);
DisplayUserSpecifiedWindow = IConsoleManager::Get().RegisterConsoleCommand(TEXT("DisplayWindow"), TEXT("test"), FConsoleCommandWithArgsDelegate::CreateLambda(
[&](const TArray< FString >& Args)
{
FString WindowTitle;
for (FString Arg : Args)
{
WindowTitle += Arg;
WindowTitle.AppendChar(' ');
}
this->DisplayWindow(WindowTitle);
}
), ECVF_Default);
- Inside ShutdownModule, add the following code:
if(DisplayTestCommand)
{
IConsoleManager::Get().UnregisterConsoleObject(DisplayTestCommand);
DisplayTestCommand = nullptr;
}
if(DisplayUserSpecifiedWindow)
{
IConsoleManager::Get().UnregisterConsoleObject(DisplayUserSpecifiedWindow);
DisplayUserSpecifiedWindow = nullptr;
}
- Implement the following function in the editor module (Chapter_10Editor.h):
void DisplayWindow(FString WindowTitle)
{
TSharedRef<SWindow> CookbookWindow = SNew(SWindow)
.Title(FText::FromString(WindowTitle))
.ClientSize(FVector2D(800, 400))
.SupportsMaximize(false)
.SupportsMinimize(false);
IMainFrameModule& MainFrameModule =
FModuleManager::LoadModuleChecked<IMainFrameModule>
(TEXT("MainFrame"));
if (MainFrameModule.GetParentWindow().IsValid())
{
FSlateApplication::Get().AddWindowAsNativeChild
(CookbookWindow, MainFrameModule.GetParentWindow()
.ToSharedRef());
}
else
{
FSlateApplication::Get().AddWindow(CookbookWindow);
}
}
- Compile your code and launch the editor.
- Play the level, and then hit the tilde key to bring up the console.
- Type DisplayTestCommandWindow and hit Enter:
![](assets/639eb05b-4ada-4f76-96ed-3e94259015d3.png)
- You should see our tutorial window open up:
![](assets/f08671c4-aad4-4102-85ab-e0906f8a10ca.jpg)