Fix: Reset simulation state on clothes disable in OnSetClothesState #2

Merged
lotsofbears merged 2 commits from crmbz/KK_AnisotropicMorph:master into master 2026-06-16 10:36:21 +00:00
Contributor

Problem

When a clothing slot disables a bone modifier (via OnSetClothesState),
Active is set to false but the simulation history is not cleared.
When the modifier is re-enabled (clothes removed/changed), the physics
simulation resumes from stale state — causing a visible snap/jump as the
bone tries to reconcile its current position with an outdated _prevPosition,
_prevVelocity, _prevRotation and _prevAngularVelocity.

Fix

Call OnChangeAnimator() and BoneModifierData.Clear() after setting Active = false
in BoneModifier.cs. OnChangeAnimator() resets simulation history (position, rotation,
velocity, angular velocity, scale accumulators), BoneModifierData.Clear() clears stale
ABMX offsets that were still being applied while inactive.

Change

BoneModifier.cs, inside OnSetClothesState():

Active = false;
OnChangeAnimator(); // Reset simulation history to prevent snap artifact on re-enable
BoneModifierData.Clear(); // Clear stale ABMX offsets so they stop being applied while inactive
return;

Tested with breast and butt bones, clothes on/off and state cycling.

Reproduction

  1. Set LinearGravity to -1 (breasts float upward)
  2. While modifier is active/visible, equip a bra (DisableClothed: Bra checked)
  3. Breasts remain frozen in the upward-stretched position with bra equipped
  4. LinearGravity slider has no effect while clothed
  5. Only recovers after removing the bra
## Problem When a clothing slot disables a bone modifier (via `OnSetClothesState`), `Active` is set to `false` but the simulation history is not cleared. When the modifier is re-enabled (clothes removed/changed), the physics simulation resumes from stale state — causing a visible snap/jump as the bone tries to reconcile its current position with an outdated `_prevPosition`, `_prevVelocity`, `_prevRotation` and `_prevAngularVelocity`. ## Fix Call `OnChangeAnimator()` and `BoneModifierData.Clear()` after setting `Active = false` in `BoneModifier.cs`. `OnChangeAnimator()` resets simulation history (position, rotation, velocity, angular velocity, scale accumulators), `BoneModifierData.Clear()` clears stale ABMX offsets that were still being applied while inactive. ## Change `BoneModifier.cs`, inside `OnSetClothesState()`: Active = false; OnChangeAnimator(); // Reset simulation history to prevent snap artifact on re-enable BoneModifierData.Clear(); // Clear stale ABMX offsets so they stop being applied while inactive return; Tested with breast and butt bones, clothes on/off and state cycling. ## Reproduction 1. Set LinearGravity to -1 (breasts float upward) 2. While modifier is active/visible, equip a bra (DisableClothed: Bra checked) 3. Breasts remain frozen in the upward-stretched position with bra equipped 4. LinearGravity slider has no effect while clothed 5. Only recovers after removing the bra
Prevents frozen-pose artifact when modifier is re-enabled after clothing
removal. OnChangeAnimator() resets simulation history, BoneModifierData. Clear()
clears stale ABMX offsets that were still being applied while inactive.
(and version bumped to 0.25.1)
Near-zero bust bone scale on males causes InverseTransformPoint to produce
astronomical values, resulting in violent spike/stretch artifacts on male
chest bones, especially at low framerates (reproducible below ~24 FPS).

Bumped version to 0.25.2.
Owner

I'd call this plugin old and busted. A new iteration (with the same name) resides in https://github.com/obedientGolem/KoikPlugins. It's still WIP though.
I'll merge PR anyways though, because why not.

I'd call this plugin old and busted. A new iteration (with the same name) resides in https://github.com/obedientGolem/KoikPlugins. It's still WIP though. I'll merge PR anyways though, because why not.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lotsofbears/KK_AnisotropicMorph!2
No description provided.