diff --git a/source/blender/blenkernel/BKE_material.hh b/source/blender/blenkernel/BKE_material.hh index 01866dff9a4..34be7392e74 100644 --- a/source/blender/blenkernel/BKE_material.hh +++ b/source/blender/blenkernel/BKE_material.hh @@ -95,7 +95,11 @@ void BKE_object_material_array_assign( Main *bmain, Object *ob, Material ***matar, int totcol, bool to_object_only); short BKE_object_material_slot_find_index(Object *ob, Material *ma); -bool BKE_object_material_slot_add(Main *bmain, Object *ob); +/** + * \param set_active: Set the newly added slot as active material slot of the object. Usually that + * is wanted when adding a material slot, so it's the default. + */ +bool BKE_object_material_slot_add(Main *bmain, Object *ob, bool set_active = true); bool BKE_object_material_slot_remove(Main *bmain, Object *ob); bool BKE_object_material_slot_used(Object *object, short actcol); diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index a19074ff59b..3df78387948 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -2441,7 +2441,11 @@ Material *BKE_grease_pencil_object_material_ensure_from_brush(Main *bmain, /* check if the material is already on object material slots and add it if missing */ if (ma && BKE_object_material_index_get(ob, ma) < 0) { - BKE_object_material_slot_add(bmain, ob); + /* The object's active material is what's used for the unpinned material. Do not touch it + * while using a pinned material. */ + const bool change_active_material = false; + + BKE_object_material_slot_add(bmain, ob, change_active_material); BKE_object_material_assign(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF); } diff --git a/source/blender/blenkernel/intern/material.cc b/source/blender/blenkernel/intern/material.cc index 3250f472082..bf976f4a53a 100644 --- a/source/blender/blenkernel/intern/material.cc +++ b/source/blender/blenkernel/intern/material.cc @@ -1322,7 +1322,7 @@ short BKE_object_material_slot_find_index(Object *ob, Material *ma) return 0; } -bool BKE_object_material_slot_add(Main *bmain, Object *ob) +bool BKE_object_material_slot_add(Main *bmain, Object *ob, const bool set_active) { if (ob == nullptr) { return false; @@ -1332,7 +1332,9 @@ bool BKE_object_material_slot_add(Main *bmain, Object *ob) } BKE_object_material_assign(bmain, ob, nullptr, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF); - ob->actcol = ob->totcol; + if (set_active) { + ob->actcol = ob->totcol; + } return true; }