Nodes/ComfyUI-Przewodo-Utils/Swap any Two values in a comparison
ComfyUI Node

Swap any Two values in a comparison

A comparator-driven valve for any two values

By przewodo·Created about a year ago·Updated 4 months ago· 4
Swap any Two values in a comparison
  • value_a
  • value_b
  • input_a
  • input_b
  • input_a
  • input_b
comparisona == b

Here's the pattern: you have two things - two prompts, two models, two latents, two paths - and you want them to swap places depending on some comparison that's true or false. Maybe a stronger model should take the foreground slot when a step count crosses a threshold, or one prompt should become primary when the seed is odd. That's a comparator driving a routing valve, and it's fiddly to build from scratch: you'd normally need a compare node, a boolean, and a switch wired together, plus careful polarity.

This node fuses them. It compares two values with one of the six standard operators, and based on the result, swaps or doesn't swap two other inputs before handing them out. In the plumbing taxonomy it's an A/B switch with the selector replaced by a live comparison - the graph decides, you never touch a widget.

How it works

There are two pairs of things here, and keeping them straight is the entire trick of this node:

  • value_a / value_b - the comparison operands. These get tested with comparison (==, !=, <, >, <=, >=).
  • input_a / input_b - the payload that gets routed.

If the comparison is true, the outputs come out swapped: output input_a carries input_b's value and vice versa. If false, they pass through unchanged. So you're not comparing the things you swap - you're comparing condition values (numbers, strings, whatever) and routing the payloads based on that condition. That's the flexibility: your condition can be "frame count > 60" while the payload is two completely different images.

All four input sockets are wildcard-typed, so both the comparison operands and the payloads can be anything.

The inputs that matter

  • value_a / value_b - the condition. Whatever you're comparing.
  • comparison - the operator, from the six-way dropdown.
  • input_a / input_b - the values that get swapped (or not).

Outputs: input_a and input_b, in original or swapped order.

Installing it

Part of ComfyUI-Przewodo-Utils. ComfyUI Manager → search the pack, or:

cd ComfyUI/custom_nodes
git clone https://github.com/przewodo/ComfyUI-Przewodo-Utils.git

Restart. Pure Python, no extra deps.

Where people get tripped up

The three-pair design is the classic source of confusion - people wire the values they want to swap into value_a/value_b and then wonder why nothing changes. Remember: value_* is the condition, input_* is the payload. They can even be the same data (compare A and B, then swap A and B), but they don't have to be, and that separation is the point.

One more honest caveat: this is a niche, personal-pack node. If your needs are simpler - just "swap these two when a boolean is set" - the pack's own SwapAnyCondition is the lighter tool, and if you need to swap images specifically, there's a typed SwapImageComparison that keeps sockets honest. This one is the general-purpose version: most powerful, most footguns, best when the condition genuinely isn't a raw boolean.

CategoryPrzewodoUtils

Inputs (5)

NameTypeDefaultDescription
value_a*First value for comparison operation. Used as left operand in the comparison
value_b*Second value for comparison operation. Used as right operand in the comparison
comparisonCOMBOa == bComparison operation to evaluate between value_a and value_b. If true, inputs are swapped
input_aopt*First input value to swap. Will be returned as 'input_b' if comparison is true, otherwise as 'input_a'
input_bopt*Second input value to swap. Will be returned as 'input_a' if comparison is true, otherwise as 'input_b'

Outputs (2)

NameTypeDescription
input_a*
input_b*