Docs
Download

Variables

Values your add-on keeps in memory while it runs, and when to use a property instead.

A variable is a named place for a value while your add-on runs. You give it a starting value, nodes change it, and later nodes read the new value. A variable lives in memory only: it isn't saved in the .blend file, and it doesn't show up as a field in the interface.

The nodes are in Variables: Local Variable and Global Variable create one, Get Variable reads it, Set Variable changes it.

Local or global

Local variableGlobal variable
ExistsFrom its node to the end of one flow, each time that flow runsOnce for the whole add-on
Starts at its Initial ValueEvery time the flow passes the nodeWhen the add-on loads (and on every rebuild while you develop)
Usable fromNodes after it in the same flow, same treeEvery flow in every tree
Typical useA total in a loop, an intermediate result you use several timesA counter, a "running" flag of a modal operator or a timer, a cache

Start with a local variable. It can't be changed by something you didn't expect, and it's back at its starting value the next time. Make it global when two flows need the same value: an operator writes it and a panel reads it, or a timer needs to know what the last run did.

Variable or property

A property also stores a value, but it belongs to Blender data (the scene, an object, the add-on's preferences), is saved with the file, can be undone and can be drawn as a field in a panel.

Use a property whenUse a variable when
The user should see or edit the valueOnly your nodes use the value
It should be saved in the .blend fileLosing it when Blender closes is fine
It belongs to a scene, object or other dataThere's one value for the whole add-on, or one per run
Undo should restore itIt's internal state: a counter, a flag, a cache
It holds a number, text, a color, a pointer to Blender dataIt holds anything, including Python objects a property can't store

A global variable keeps its value across files: opening another .blend doesn't reset it, but enabling the add-on again or a rebuild while you develop does.

Names

The label of a Local Variable or Global Variable node is the variable's name in the pickers and in the generated code. A Local Variable labeled Total becomes total. A Global Variable labeled Click Count becomes _click_count, read and written through get_click_count() and set_click_count(), so other files of the add-on can import it.