function OnSelectionChanged(oldSelection, newSelection, added, removed)
    local availableOrders, availableToggles, buildableCategories = GetUnitCommandData(newSelection)
    local isOldSelection = table.equal(oldSelection, newSelection)

    if not gameUIHidden then
        if not isReplay then
            import('/lua/ui/game/orders.lua').SetAvailableOrders(availableOrders, availableToggles, newSelection, isOldSelection)
        end
        -- todo change the current command mode if no longer available? or set to nil?
        import('/lua/ui/game/construction.lua').OnSelection(buildableCategories, newSelection, isOldSelection)
    end
        
    if not isOldSelection then
        import('/lua/ui/game/selection.lua').PlaySelectionSound(added)
        import('/lua/ui/game/rallypoint.lua').OnSelectionChanged(newSelection)
    end
end