UE5 Viewport Selection Change Event setup (python/PySide)

Been slogging through docs and attempting several things to try to get an event hooked up in Python/PySide2 so I can be notified when the viewport selection changes (so I could pull out data for a tool)

What I’ve found is that in my PySide2 QMainWindow I did the following:

class MyMainWindow(QtWidgets.QMainWindow):
    def __init__(self,parent=None):
        self.ue_lvlsubsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
        self.selection_set = self.ue_lvlsubsystem.get_selection_set()

    def update_viewport_selection(self, selection_set):
        selected_elements = selection_set.get_selected_objects()
        # do stuff with your selected objects

Just wanted to share this so it might help other people in the future :slight_smile:

1 Like