aaa_index - chrisgoringe/Comfy-Custom-Node-How-To GitHub Wiki
This repository is being retired
Everything here will (eventually) be part of docs.comfy.org.
A shameless plug
I've learned most of what I know by writing custom nodes and solving problems as I've gone along. I try to make the code I write as clean and clear as I can, if only so that I can read it in the future. So this is a shameless plug for some of my custom nodes - the excuse being that you can read the code and see how I did things.
- Use Everywhere - nodes that edit the prompt before it gets sent to invisibly connect broadcast nodes to unconnected inputs.
- Image picker - nodes that pause the execution and let you choose an image to continue with. Illustrates adding a route to the api so the javascript can message the backend in mid execution.
- Variation Seeds - aka noise hijack - illustrates a way of changing the core backend behaviour without rewriting the core code.
Unofficial practical collaborative Q&A on developing custom nodes
If you've got a question not answered here, post it as an issue. The contents of this Q&A are things I've learned as I've got into custom node development. It's not systematic or complete. But I like working out how things work, so if you ask an interesting question it's likely I'll try to answer it!
Starting Points
- ComfyUI uses nodes to do all the work of stable diffusion. It comes with lots of them out of the box, but if you want to do something that can't be done with one that already exists, you can create new nodes.
- ComfyUI-Manager is your go-to for finding and installing custom nodes.
- ComfyUI dev on matrix is a friendly place to ask questions.
Writing a simple custom node
In the ComfyUI repository, the folder custom_nodes
you'll find example_node.py.examples
. That's worth reading.
Going further
nodes.py
in the top level of the ComfyUI directory has the definitions of lots of the built in nodes. Look at the code for a node that does something a bit like you want.
Here are some guides on how to do things that have been contributed:
Backend (python)
Stuff which (might) involve the UI (javascript)
- What order are nodes executed in?
- Inputs which take anything
- Custom data types
- Communicating between javascript and python
- From JavaScript to Python: Add to the API
- From Python to Javascript: Messages to nodes
- A worked example: Passing control to javascript
Extending the UI
- Initial concepts in UI extension
- Some more advanced UI extension
- Custom Widgets
- Getting control_after_generate
- Changing the value of a widget
- Adding and removing widgets
- Setting the color of an input dot
- Adding to the canvas menu
Javascript core internals
Odds and Ends
Credits
The following people have answered questions, or asked good ones, or made helpful suggestions, or written good clean code that I learned from, or submitted PRs to improve this.
Their inclusion here doesn't imply that they know about this wiki, or approve of it! Just that they have been part of making it happen, whether they know that or not :).
- chrisgoringe
- Lerc
- pitzips
- @wasasquatch:matrix.org on ComfyUI dev
- TinyTerra
- Poyojo
- drago87
- lakmeer