Nodes/Avatar Graph/Object Set Active Material Index
ComfyUI Node

Object Set Active Material Index

Which material slot is 'active'? You decide, in a node

By avatechai·Created 3 years ago·Updated 2 years ago· 264
Object Set Active Material Index
  • BPY_OBJ
  • BPY_OBJ
value0

ObjectSet_ActiveMaterialIndex is a setters' node: feed it an object and an integer, and it sets which material slot on that object is currently "active." In Blender, a mesh can hold many material slots, and a whole family of operations - assigning a material to a face selection, removing a slot, moving slots around - acts on whichever slot is active at the moment. This node is how you choose that moment from inside a ComfyUI graph.

Why you'd reach for it

In the Avatar Graph pipeline you usually have one texture per mesh layer, so there's not much slot juggling on the happy path. The node earns its place the second your mesh is more complex than a single material. Say you've got an avatar body mesh with separate slots for skin, clothing, and hair: before you assign a new material to a face group or manipulate a specific slot, you set the index here first, and the operation that follows will target the right one. It's the graph equivalent of clicking a slot in the Material Properties panel, and it's the prerequisite for any slot-sensitive step downstream.

How it works

This is one of the pack's auto-generated ObjectSet_ nodes. Peek at blender/ops_mesh.py and you'll see a list of object attributes (bpy_object_member) that get turned into setter nodes by create_obj_setter_class. Each setter does something beautifully simple - setattr(BPY_OBJ, 'active_material_index', value) - then passes the object through untouched. No Blender operator is invoked, no scene resets are triggered beyond the pack's usual ones. It's just a property write on the object handle.

That simplicity is worth understanding, because it means this node is pure state mutation. The integer you set lives on the object; the node does not validate that the index is within range of the object's actual slot list. Set it to 3 on a mesh with two slots and nothing crashes - the active slot just points at empty air until you add more materials.

Inputs and outputs

  • BPY_OBJ (optional) - the object whose active material slot you're setting.
  • value (INT, default 0) - the slot index. 0 is the first slot, which is the right default for a freshly textured single-material mesh.

Output: BPY_OBJ, the same object, ready for whatever material operation comes next.

Install and gotchas

Part of the full pack - ComfyUI Manager (search "Avatar Graph") or:

cd ComfyUI/custom_nodes
git clone https://github.com/avatechai/avatar-graph-comfyui.git
cd avatar-graph-comfyui && python -m pip install -r requirements.txt

Reminders that apply to every node in this pack: it pins bpy==3.6.0, so your Python needs to be 3.10; first load downloads the ~2.5GB SAM checkpoint and mediapipe models; and the headless Blender scene resets to factory settings each run, so objects - and the material index you just set on them - are rebuilt from scratch every time you execute the graph. Want the live avatar preview instead of just the GLB/GLTF export? Launch ComfyUI with --enable-cors-header.

ObjectSet_ActiveMaterialIndex is a small utility, but it's the kind of small utility that silently decides whether your material assignment lands on the right slot. When multi-material meshes are in play, it's the difference between working and wondering why the wrong part of the model changed color.

Categoryblender

Inputs (2)

NameTypeDefaultDescription
BPY_OBJoptBPY_OBJ
valueoptINT0

Outputs (1)

NameTypeDescription
BPY_OBJBPY_OBJ