Node.copy is supposed to be called when a node is copied. In particular, this should allow developers of
ShaderNodeCustomGroup to recreate internal node_tree if it depends on node options/properties.
However, this does not happen when node is copied into another material with operator
ops.material.new. This results in that all node trees are shared between materials and adjusting trees according to options/properties affect all materials.
The condition when the method shold be called is determined by this line at source/blender/rendkernel/intern/node.c, in function
bool do_copy_api = !((flag & LIB_ID_CREATE_NO_MAIN) || (flag & LIB_ID_COPY_LOCALIZE));
The flags are described as
/** Create datablock outside of any main database - similar to 'localize' functions of materials etc. */ and
/** Generate a local copy, outside of bmain, to work on (used by COW e.g.). */
When copying material node_tree, the flags to copy nodes are set
at source/blender/rendkernel/intern/node.c, in function
/* We never handle usercount here for own data. */ const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/** Do not affect user refcount of datablocks used by new one (which also gets zero usercount then). */ and it’s included into
Altough, refcounts of node_trees of copied
ShaderNodeCustomGroups are effectively affected by such copying.
Could someone or @mont29 please explain the logic behind this, and hint if the behaviour of not calling
copy can be ever fixed?