[SOLVED] How to Create Custom Nodes with Dynamic, Auto-Expanding Inputs in ComfyUI #10324
ansorre
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
dynamic_inputs_example.zip
With Gemini 2.5 Pro, I investigated how to create custom nodes with dynamic inputs—those inputs that, once you've connected one, immediately create a new, disconnected one, available for adding further inputs. Since this feature isn't yet well documented in the official ConfyUI documentation, and since it took me a couple of days of work to get it right, I decided to have Gemini write a working example and a markdown file with a mini-guide on how to do this. I hope it will be useful to others and possibly added to the official documentation if deemed appropriate. I'm attaching the file with the example and the markdown doc.
I also add the MD text here just in the case other people/LLMs searche for this on the Internet.
Thank you for your attention.
How to Create Custom Nodes with Dynamic, Auto-Expanding Inputs in ComfyUI
This guide explains how to create a "normal" custom node where new input slots are added automatically as the user connects the last available one. This advanced technique requires a combination of a Python file for the backend logic and a JavaScript file for the frontend behavior.
The Core Concept
The Python script defines the basic node structure and its server-side execution logic. The JavaScript script "enhances" this node in the browser, watching for connection changes and dynamically adding or removing input slots.
Step 1: The Python Node (
__init__.py)This file sets up the node's foundation.
Key Points:
WEB_DIRECTORY = ".": This is critical. It tells ComfyUI to serve the contents of this node's folder (including our JavaScript file) to the browser.INPUT_TYPES: You only need to define the first dynamic input (e.g.,input_1). Use("*",)as the type to create a universal "ANY" input that accepts all data types.executefunction: It must accept**kwargsto handle an unknown number of inputs. You can then loop throughkwargsto collect all providedinput_...values into a list for easy processing.Example
__init__.py:Step 2: The JavaScript Enhancement (
.jsfile)This file brings the node to life in the user interface.
Key Points:
app.registerExtension: The standard way to add custom frontend behavior.nodeCreated(node): This function is called for every node added to the canvas. We must first check if thenode.constructor.typematches our node's class name from Python.onConnectionsChangehook: This is the core of the magic. We augment the existing function to run our custom logic after any connection change occurs.Example
my_node_script.js:Step 3: File Structure and Final Steps
Your files must be placed in a dedicated folder inside
ComfyUI/custom_nodes/.Final Checklist:
Ctrl+Shift+RorCmd+Shift+R) to ensure the new JavaScript file is loaded.Beta Was this translation helpful? Give feedback.
All reactions