🧮 Set Prompt Variable 🧮
Feed a variable into your prompt chain without a wildcard file
- context
- context
Adaptive Prompts lets you assign a variable inline by tagging a wildcard or bracket with ^name, like __color^c__, and retrieve it later with __^c__. That's great when the variable's value should itself be randomized. SetPromptVariable covers the other case: you want to hand a variable a fixed value, or a small hand-picked list of values, from outside that flow - without creating a whole .txt wildcard file just to hold three character names.
How it works
You give it a variable name and a block of data. Here's the detail that trips people up: the data field does not resolve brackets or wildcards. Each newline in data becomes a separate literal candidate value for that variable - it's functionally an inline, un-randomized wildcard list, not a place to write dynamic-prompt syntax. If you type {red|blue} into data, you get the literal string {red|blue} stored as the variable's value, not a random pick between the two. If you want the value itself randomized, do that upstream with a Prompt Generator and set the variable via the ^name syntax instead - this node is for planting fixed content.
The node produces no prompt text of its own. Its only output is a context DICT, which is the same context object that chains between Prompt Generator nodes to carry variable state forward. You feed this node's context output into a Prompt Generator's context input (directly, or via PromptContextMerge if you're combining it with variables from elsewhere), and from that point on __^yourvariable__ resolves inside that generator.
The inputs and outputs that matter
variable(default"var") - the name you'll retrieve it by later, e.g. set this tochar1and retrieve with__^char1__.data(multiline, default empty) - the literal value(s), one per line if you want multiple candidates for that variable to be picked between.context(optional input) - an existing context to extend. Leave it unwired if this is the first node in the chain; wire it if you're adding a variable to a chain that already has others so you don't lose them.- Output:
context(DICT) - pass this downstream.
How to install it
Same install as every node in this pack: search comfyui-adaptiveprompts in ComfyUI Manager, or clone it manually -
cd ComfyUI/custom_nodes
git clone https://github.com/Alectriciti/comfyui-adaptiveprompts
- then restart ComfyUI. No models, no extra dependencies to install.
Common issues & troubleshooting
The variable doesn't show up downstream. This is almost always a broken chain, not a broken node. Every hop between where you set a variable and where you retrieve it needs its context output wired into the next node's context input - SetPromptVariable in, Prompt Generator (or another SetPromptVariable, or PromptContextMerge) out, and so on. Drop one link in that chain and the variable never arrives.
You expected randomization and got the literal text back. Re-read the tooltip on data: it's explicitly not resolved for brackets or wildcards at this stage. If you need the value itself to vary between runs, assign it inline in a Prompt Generator with ^name syntax instead of through this node - SetPromptVariable is for injecting known, fixed data, not for generating new random content.
You have several sources of variables to merge. SetPromptVariable only takes one incoming context. If you're merging variables set by this node with variables coming out of a separate Prompt Generator chain, route both through PromptContextMerge before they reach the generator that needs to see all of them.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| variable | STRING | var | The variable to store the data in. In a Prompt Generator, this can be retrieved with __^var__ |
| data | STRING | Each newline creates a separate data entry for this variable. Brackets & Wildcards do not get resolved at this stage. | |
| contextopt | DICT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| context | DICT | — |