Editor Utility Widget Launcher

A quick Menu Class to launch Editor Utility Widgets

Expanding off of our base class, let's make a quick class to launch our Editor Utility Widgets!

Launching an Editor Utility Widget (EUW)

The code to launch an EUW is relatively straight forward, we just need to spawn a tab using the EditorUtilitySubsystem:

EditorUtilitySubsystem = unreal.get_editor_subsystem(unreal.EditorUtilitySubsystem)

asset = unreal.load_asset("/Game/Path/To/EUW")
EditorUtilitySubsystem.spawn_and_register_tab(asset)

We'll create a generic function to launch an EUW from its asset path:

def launch_editor_utility_widget(asset_path: str):
    """Launch the given utility widget from its asset path"""

    # ensure a valid asset path was provided
    if not isinstance(asset_path, str):
        unreal.log_error(f"The given input is not an asset path: {asset_path}")
        return
    
    if not EditorAssetLibrary.does_asset_exist(asset_path):
        unreal.log_error(f"The given asset path does not exist: {asset_path}")
        return
    
    # open the EUW
    asset = EditorAssetLibrary.load_asset(asset_path)
    EditorUtilitySubsystem.spawn_and_register_tab(asset)

The EditorUtilityWidgetMenuTool

With our new function and existing PythonMenuTool base class, this is all we need to declare in our new EUW Launcher class:

@unreal.uclass()
class EditorUtilityWidgetMenuTool(PythonMenuTool):
    """
    menu tool base class to launch specified Editor Utility Widgets
    """
    widget_path = "/Game/editor/utility/widget/path"

    @unreal.ufunction(override=True)
    def execute(self, context):
        """Open the EUW when pressed"""
        launch_editor_utility_widget(self.widget_path)

That's all there is to it, on execute it will launch the widget_path declared on the class!


Demo Tool

Here's an example tool, the Meta Viewer GUI:

@unreal.uclass()
class MetaViewerTool(EditorUtilityWidgetMenuTool):
    name = "meta_viewer"
    display_name = "Meta Viewer GUI"
    tool_tip = "Launch the Meta Viewer tool"
    widget_path = "/PythonRecipeBook/sample_tools/meta_viewer"

This provides a simple menu class setup we can make for each of our first-class Editor Utility Widget tools

Pressing the menu button launches our tool:

Last updated