Fix: Retain slot name when baking action

Previously when an action was baked, the slot name was not retained.
This causes problems when switching between actions because the slot
will not automatically be assigned.

This is now fixed by ensuring that the name of the last assigned slot
is used to create the new slot.

Pull Request: https://projects.blender.org/blender/blender/pulls/136814
This commit is contained in:
Christoph Lendenfeld
2025-04-03 10:18:15 +02:00
committed by Christoph Lendenfeld
parent 4c9c9af2d6
commit 28d0bef706
2 changed files with 6 additions and 2 deletions

View File

@@ -393,6 +393,7 @@ def bake_action_iter(
# in case animation data hasn't been created
atd = obj.animation_data_create()
old_slot_name = atd.last_slot_identifier[2:]
is_new_action = action is None
if is_new_action:
action = bpy.data.actions.new("Action")
@@ -406,7 +407,7 @@ def bake_action_iter(
# A slot needs to be assigned.
if not atd.action_slot:
slot = action.slots.new(obj.id_type, obj.name)
slot = action.slots.new(obj.id_type, old_slot_name or obj.name)
atd.action_slot = slot
# Baking the action only makes sense in Replace mode, so force it (#69105)

View File

@@ -76,6 +76,7 @@ class ObjectBakeTest(unittest.TestCase):
self.assertNotEqual(action, self.obj.animation_data.action, "Expected baking to result in a new action")
baked_action = self.obj.animation_data.action
self.assertEqual(len(baked_action.slots), 1)
self.assertEqual(baked_action.slots[0].name_display, action.slots[0].name_display)
channelbag = anim_utils.action_get_channelbag_for_slot(baked_action, self.obj.animation_data.action_slot)
self.assertIsNotNone(channelbag)
@@ -137,12 +138,14 @@ class ObjectBakeTest(unittest.TestCase):
self.assertIsNotNone(self.obj.animation_data.action_slot)
self.assertIsNotNone(obj2.animation_data.action_slot)
self.assertNotEqual(self.obj.animation_data.action_slot, obj2.animation_data.action_slot)
original_slot = obj2.animation_data.action_slot
anim_utils.bake_action_objects([(obj2, None)], frames=range(0, 10), bake_options=OBJECT_BAKE_OPTIONS)
self.assertNotEqual(action, obj2.animation_data.action, "Expected baking to result in a new action")
baked_action = obj2.animation_data.action
self.assertEqual(len(baked_action.slots), 1)
self.assertEqual(original_slot.name_display, baked_action.slots[0].name_display)
channelbag = anim_utils.action_get_channelbag_for_slot(baked_action, baked_action.slots[0])
for fcurve in channelbag.fcurves: