On Selection Changed Callback
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:
Adding our Function to the Callback
To register our function, we can run the following logic:
This will get the selection set from the LevelEditorSubsystem and add our Python function to it
And now, any time we select something in the viewport we get
Removing our Function from the Callback
When we're done with our tool / use case we can use the remove_callable
function to disconnect our callback function:
Last updated