ComfyUI Node

Modulo

The Easiest Way to Make Things Loop and Cycle

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Modulo
  • value_a
  • value_b
  • MATCHTYPE

UC_MathModulo returns the remainder after division. 17 % 5 is 2, 100 % 10 is 0. It's the node behind a surprising amount of "smart" behavior in ComfyUI, because a remainder is how you wrap a number back into a range - which is what makes things loop, cycle, and repeat.

Why you'd reach for it

Modulo is the cycle machine. The canonical pattern is index % count: take a running frame counter or seed index and wrap it into a bounded range, so seed 0, 5, 10 all map back into a set of 5. That's how you rotate through LoRA variants, cycle through prompt presets, or alternate between two denoise strengths every other frame. It's also how you trigger "every Nth step" logic - n % N == 0 only fires on multiples of N, and fed into a UC_MathCompare with Equal, it becomes a clean gate. If you've ever wanted a workflow that does something different on frame 3, 6, 9… modulo is the mechanism.

How it works

Two inputs, value_a and value_b, both accepting int or float, and a single output that mirrors the input type. The implementation has one deliberate safety feature: if the divisor is zero, it returns 0 instead of crashing - consistent with the pack's divide node. The subtlety to remember is that Python's remainder follows the sign of the divisor, so -7 % 3 is 2, not -1. It only bites in edge cases, but it's the kind of thing that produces a "why is my cycle off by one" moment.

The inputs that matter

  • value_a - the number being divided.
  • value_b - the divisor, the thing you're cycling around.

Installing it

Part of ComfyUI-UtilsCollection. ComfyUI Manager → search "ComfyUI-UtilsCollection" → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart. No models; the pack's requirements are just opencv-python and typing-extensions.

The takeaway

Modulo is one of those nodes you ignore for months and then can't imagine building without - the moment you want repetition, it's the tool. Pair it with a counter, a compare, and the pack's UC_LogicIF and you've got branching loops without writing a single line of Python. And if an old ComfyUI-LogicMath workflow is where you met this node before, this is its replacement: accept ComfyUI's swap prompt and uninstall LogicMath so the two don't sit in your node list together.

Categoryutils/math

Inputs (2)

NameTypeDefaultDescription
value_aCOMFY_MATCHTYPE_V3
value_bCOMFY_MATCHTYPE_V3

Outputs (1)

NameTypeDescription
MATCHTYPECOMFY_MATCHTYPE_V3