OmicronNEGA:
How to draw HUD in editor?
TWeakPtr<SLevelEditor> editor = LevelEditor.GetLevelEditorInstance();
TSharedPtr<SLevelEditor> PinnedEditor( editor.Pin() );
if( PinnedEditor.IsValid() )
{
TSharedPtr<SLevelViewport> slevelviewport = PinnedEditor->GetActiveViewport();
...
Sometimes won’t work on Windows, but perfectly on OS X.
When I say “sometimes”, which means I tried compile code without changing anything, sometimes it compiles, sometimes fails, but most of the time, it fails. This is really odd.
I don’t know why, it just keep failing linking even if I added “LevelEditor” dependency to Build.cs file, so if above code didn’t work, then try below:
TSharedPtr<SLevelViewport> slevelviewport = StaticCastSharedPtr<SLevelViewport>(LevelEditor.GetFirstActiveViewport());
This works.
This is because the engine class SLevelEditor does not have the “LEVELEDITOR_API” macro, thus anything outside the LevelEditor Module cannot call functions of that class.