Nodes/Bjornulf_custom_nodes/๐Ÿ“Œ๐Ÿ…ฐ๏ธ Set Variable from Text
ComfyUI Node

๐Ÿ“Œ๐Ÿ…ฐ๏ธ Set Variable from Text

Name a string once, reuse it everywhere

By justUmenยทCreated 2 years agoยทUpdated about a year agoยท 545
๐Ÿ“Œ๐Ÿ…ฐ๏ธ Set Variable from Text
    • STRING
    โ—„variable_namevariable_nameโ–บ
    โ—„text_valueโ€”โ–บ

    Bjornulf's Advanced Write Text node has a variable syntax - write <character_name> somewhere in your prompt and it'll pull in whatever value you've registered under that name, instead of you retyping "a tall woman with red hair and a scar" in five different write-text nodes across your graph. Set Variable from Text is how you register that value in the first place. It's small, it's plumbing, and it's the thing that makes the pack's variable system actually usable instead of a syntax nobody sets up.

    How it works

    You give it a variable_name and a text_value. Under the hood, that registers the name so any of the pack's other "variables" nodes - Advanced Write Text, Global Variables, and the rest - can reference it later by that name instead of you re-wiring or retyping the same string over and over. The output is simply the text_value you passed in, unchanged, so the node also works as a normal pass-through if you want to both register a variable and keep using the text immediately in the same branch.

    This pairs naturally with the pack's {option_one|option_two|option_three} bracket syntax - the same old A1111-style wildcard trick the wider community still reaches for to get prompt variety without writing a separate prompt for every variant. Set a randomized description once with a name, reference <that_name> everywhere it needs to show up, and every reference stays in sync when you reroll the seed. Without a named variable, you'd have to keep several Write Text nodes manually in agreement by hand.

    The inputs and outputs that matter

    • variable_name (STRING, default "variable_name") - the name you'll reference later as <name> in an Advanced Write Text node or similar.
    • text_value (STRING) - the text that name should resolve to.
    • Output - a single STRING, the same text_value you passed in, so you can chain straight into another node without a dead end.

    How to install it

    ComfyUI Manager โ†’ search Bjornulf_custom_nodes โ†’ install โ†’ restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/justUmen/Bjornulf_custom_nodes
    pip install -r Bjornulf_custom_nodes/requirements.txt
    

    No special dependency for this node - it's part of the pack's text/variable subsystem, which is pure Python string handling.

    Common issues & troubleshooting

    The variable isn't resolving anywhere. Double-check the name matches exactly - <character_name> in your Advanced Write Text node has to be spelled identically to the variable_name you set here, including case. A typo just leaves the literal <name> text sitting in your prompt instead of erroring.

    I set the same variable name twice in one graph. Behavior here isn't something to guess at - if two Set Variable from Text nodes register the same name, treat it as undefined which one wins and avoid the collision entirely by giving each variable a distinct name.

    I want the variable to change every run. This node just sets a fixed string - it doesn't randomize on its own. Feed it output from a randomized source (the pack's {a|b|c} bracket syntax inside a Write Text node, or a Random Text node) as its text_value if you want the registered variable itself to vary.

    Why not just use a Write Text node directly? You can, for a single use. The variable system earns its keep once the same text needs to appear in more than one place - a character description referenced by both a Write Text node and a save-folder path, for instance - where hand-syncing multiple nodes is exactly the kind of thing that quietly drifts out of sync.

    CategoryCustom

    Inputs (2)

    NameTypeDefaultDescription
    variable_nameSTRINGvariable_nameโ€”
    text_valueSTRINGโ€”

    Outputs (1)

    NameTypeDescription
    STRINGSTRINGโ€”