Skip to content

Commit

Permalink
Fix VRCAnimatorPlayAudio not getting its source path adjusted when …
Browse files Browse the repository at this point in the history
…using `Delete Unused GameObjects`. #93
  • Loading branch information
d4rkc0d3r committed Apr 17, 2024
1 parent 3ae149b commit 2c2316c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fix `#pragma shader_feature` only getting replaced by defining the keywords instead of defining them as a true value.
* Fix always disabled ParticleSystemRenderers getting deleted when `Delete Unused Components` is enabled. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/issues/91)
* Somehow the ParticleSystemRenderer component is important for the particle system to work even if it is disabled. Maybe something about sub emitters? idk
* Fix `VRCAnimatorPlayAudio` not getting its source path adjusted when using `Delete Unused GameObjects`. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/issues/93)

## v3.6.0
### Features
Expand Down
15 changes: 15 additions & 0 deletions Editor/d4rkAvatarOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,21 @@ private void FixAllAnimationPaths()
state.motion = FixMotion(state.motion, fixedMotions, layerCopyPaths[i]);
}

if (DeleteUnusedGameObjects) {
var playAudioType = Type.GetType("VRC.SDKBase.VRC_AnimatorPlayAudio, VRCSDKBase");
if (playAudioType != null) {
var pathField = playAudioType.GetField("SourcePath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
foreach (var behaviour in newLayer.layers.SelectMany(layer => layer.stateMachine.EnumerateAllBehaviours())) {
if (playAudioType.IsAssignableFrom(behaviour.GetType())) {
var path = (string)pathField.GetValue(behaviour) ?? "";
if (transformFromOldPath.TryGetValue(path, out var transform) && transform != null) {
pathField.SetValue(behaviour, GetPathToRoot(transform));
}
}
}
}
}

avDescriptor.baseAnimationLayers[i].animatorController = newLayer;
}
Profiler.StartSection("AssetDatabase.SaveAssets()");
Expand Down

0 comments on commit 2c2316c

Please sign in to comment.