布尔转整数丨类型转换
True becomes 1, False becomes 0 — and suddenly your graph math works
- 整数
ComfyUI is annoyingly strict about types. A boolean output will happily drive a switch, but the moment you want to multiply something by that boolean - or add it to a seed, or use it as a count - you get a red wire and a refusal. BoolToInt is the bridge: it takes a BOOLEAN and hands you back an INT that is literally 1 when the input is true and 0 when it's false. That's the whole node, and it's the kind of two-line tool you don't appreciate until you're three nodes deep into a filename-counter or a batch loop that needs a number from a condition.
It lives in the QING/ data-tools category of the ComfyUI-QING pack, and like its siblings (BoolInvert, IntToBool, StringToBool) it exists because core ComfyUI's primitive nodes hold values but don't convert between types. If you've spent any time in the plumbing layer - value nodes, Convert widget to input, *-typed routing - you know the shape of these things. This one just sits between a logic output and a math input.
How it works. Nothing clever under the hood: the source returns 1 if boolean else 0. No state, no caching surprises, deterministic every run, so the executor won't re-run your downstream graph unless the boolean actually changed. It's the same trick HasValue (same pack) uses when it emits an integer alongside its boolean.
The inputs and outputs that matter. Again, one of each:
boolean- aBOOLEANinput, defaultfalse. Type it, or convert the widget to an input and wire in a comparison, a switch, or aHasValue.- The output, labeled 整数 (INT), is your
1or0.
The output plugs into anything that wants a number: seed arithmetic, step counters, DynamicIntegerIncrement, an image batch index, or a float converter if the math node demands a FLOAT instead. A common pattern is chaining BoolToInt into a multiplier so a branch can be "included" (×1) or "skipped" (×0) purely from a condition - no switch node required.
How to install. ComfyUI-QING is one pack that installs together - you don't get just this node. Either search "ComfyUI-QING" in ComfyUI Manager, or clone manually:
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py
Then restart ComfyUI. The README's clone URL is typo'd (GAOSHI-QING - missing the H), so use the URL above or let Manager handle it; Chinese users can add --mirror to the dependency step for faster mirrors.
Troubleshooting. The main confusion is expectations: this outputs integers, so if your downstream widget expects a boolean back, you've got a type mismatch - chain it through IntToBool if that's genuinely what you want. And remember the output port name is Chinese (整数), which reads oddly next to English-labeled neighbors but is the same INT type. One real gotcha: 0 and 1 are integers, not floats, so a conditioning or opacity input that wants FLOAT will still complain - feed it through a number conversion rather than assuming the integer will auto-widen. It won't.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| boolean | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 整数 | INT | — |