Nodes/ComfyUI-My-Nodes/比较分流器
ComfyUI Node

比较分流器

Branch your workflow on a comparison, with both sides pre-routed

By Tagbliton·Created 2 years ago·Updated about a year ago· 11
比较分流器
  • if_True
  • if_False
  • a
  • b
  • output1
  • output2
  • boolean
mode

ComfyUI turns into a small programming language once you start wiring logic nodes, and this is one of the better ones: a comparator that takes two any-type values a and b, compares them, and routes both branches of the result. You hand it the "if true" and "if false" payloads, it compares, and you get the winner on one output, the loser on the other, plus a raw boolean. It's the "ternary operator" of the graph.

The mode dropdown gives you the six classic operators: ==, !=, >=, >, <=, <. Everything else is optional, which is the real flexibility - a, b, if_True, and if_False are all * (any-type), so you can compare numbers, strings, seeds, or even tensors and route images, latents, or text accordingly. Three outputs come out: output1, output2, and boolean.

The routing logic is worth understanding because it's subtly different from a plain switch: if the comparison is true, output1 carries if_True and output2 carries if_False. False flips them. So the node is genuinely two switches in one - you can wire output1 to the "keep going" path and output2 to the "abort/fallback" path and never need a separate NOT node. The boolean output lets you feed the raw result into other logic.

The one thing the source is honest about: tensor comparisons. If a and b are tensors, the node tries torch.equal first - and only == and != actually work that way. For the other four operators on tensors, the node silently falls back to treating the result as == and prints a warning to the console ("张量比较仅支持'=='和'!='", i.e. tensor comparison only supports == and !=). For plain numbers and strings, all six operators behave as labeled. So: use it for scalars and strings confidently; if you need element-wise tensor comparisons, this isn't the node.

Typical use: comparing a loop counter against a threshold (index >= 10), checking a seed, or comparing two strings (e.g. a file-extension check) to route different processing. It pairs naturally with the pack's "选择输出器" for simpler bool→value routing when you don't need both branches.

Install: part of ComfyUI-My-Nodes - ComfyUI Manager → search "ComfyUI-My-Nodes", or git clone https://github.com/Tagbliton/ComfyUI-My-Nodes into custom_nodes and restart. No API key, no network - this is a pure local utility, so none of the DashScope account stuff applies.

Gotchas. The tensor-operator fallback above is the only real trap. Also note the pack's display name for this node is 比较分流器 ("comparison splitter"), which describes the routing behavior better than "Digital Comparator" does - searching either name in the node list finds it. If your comparison seems to misroute, double-check that you wired if_True/if_False to the outputs you think you did, because the swap-on-false behavior catches people.

Category我的节点/Tools

Inputs (5)

NameTypeDefaultDescription
modeCOMBO6 options: ==, !=, >=, >, <=, <
if_Trueopt*
if_Falseopt*
aopt*
bopt*

Outputs (3)

NameTypeDescription
output1*
output2*
booleanBOOLEAN