ComfyUI Node

HT Dynamic Switch

The input that grows when you plug more in

By ArtHommage·Created 2 years ago·Updated about a year ago· 4
HT Dynamic Switch
    • value
    • used_input

    ComfyUI's normal switch nodes come with a fixed number of inputs - "pick one of these 4". HT Dynamic Switch, from HommageTools, is the version that grows: it starts with one input, and every time you plug something into the newest one, it spawns another. It's a first-non-empty selector that never runs out of sockets, and for branching workflows it removes a whole category of "I need one more option" rebuilds.

    How it works

    The node's secret is JavaScript. A bundled extension (ht_dynamic_switch_node.js) watches the node's connections and, whenever you connect to the highest-numbered input, adds a new inputN slot after it. So you connect input1, it adds input2; connect input2, it adds input3 - you literally grow the fan-in by using it.

    At execution, the Python side checks each input in numeric order and returns the first one that isn't empty:

    • None is skipped.
    • Empty strings ("") are skipped.
    • Empty list-like objects (length 0) are skipped.

    The first real value wins, and the node tells you which one it picked. Outputs are value (whatever type the chosen input was - it's the universal * type, so images, strings, latents all pass through) and used_input (an INT saying which input index supplied the value, e.g. 1 for input1).

    Why you'd use it

    Fallback chains are the natural fit. Say you want "use this image if provided, otherwise generate from this latent, otherwise use a placeholder" - you wire them into successive inputs and the first non-empty one flows through. That's conditional logic without a single if-node, and because the input count is dynamic, adding a fourth candidate doesn't mean rebuilding the graph.

    The used_input output is the sleeper feature. Wire it into a console logger or a switch downstream and you can log which branch actually fired, which makes debugging multi-path workflows vastly less annoying.

    Installing it

    Part of HommageTools. ComfyUI Manager → search HommageTools, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ArtHommage/HommageTools.git
    cd HommageTools && pip install -r requirements.txt
    

    Restart ComfyUI - the JavaScript only registers on a fresh page load, so if the dynamic inputs don't appear, hard-refresh the browser.

    Gotchas

    • If all inputs are empty, it raises an error rather than falling back. That's by design - a silent "nothing" is how bugs hide. Make sure at least one path always has a real value.
    • The dynamic-input magic lives in the front-end. If you load a workflow in a browser without the extension's JS loaded (e.g. a plain ComfyUI install without this pack), the node will still run - it'll just evaluate whatever inputs exist in the saved graph.
    • "Empty" means None, "", or zero-length. A tensor of zeros is not empty and will be returned happily.

    For "first valid input wins" routing with unlimited options, this is the least-fiddly node of its kind in the pack - and the input auto-growth is the kind of thing you don't realize you wanted until you've used it once.

    CategoryHommageTools

    Inputs (0)

    No inputs

    Outputs (2)

    NameTypeDescription
    value*
    used_inputINT