For any tools that rely on the current actor selection in the viewport
A neat property of the LevelEditorSubsystem is get_selection_set(), this is the Selection Set managed by the subsystem that keeps track of what's currently selected in the 3D Level / Editor World.
A callback we can make use of on this object in Python is on_selection_changed, which triggers any time the user changes their selection. This can be quite powerful for Editor Utility Widgets to be more dynamic with what ever the user has selected in their scene.
Our Callback Function
For this callback, the LevelEditorSubsystem will pass along its Selection Set when triggered to our custom function. Our function will expect to be provided the Selection Set and can go directly into its relevant logic:
defselection_tracker(selection_set: unreal.TypedElementSelectionSet):if selection_set.get_num_selected_elements():print(f"The following objects are currently selected:")for selected in selection_set.get_selected_objects():print(f"\t{selected.get_path_name()}")else:print("no objects selected!")
Adding our Function to the Callback
To register our function, we can run the following logic: