Skip to content

Commit

Permalink
fix: workaround VRCSDK bug where stale data is left in physbone state
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed May 7, 2024
1 parent 5617be4 commit f265254
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Editor/VRChat/ForceReinitPhysBonesHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#region

using UnityEngine;
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDKBase.Editor.BuildPipeline;

#endregion

namespace nadena.dev.ndmf.VRChat
{
/// <summary>
/// When domain reload is disabled, the VRChat physbones gizmo can leave outdated data in the VRCPhysBone component
/// when entering play mode. Force reinitialize the components to work around this issue.
///
/// Note that we only do this when entering play mode, as this is runtime state, not serialized state.
/// </summary>
public class ForceReinitPhysBonesHook : IVRCSDKPreprocessAvatarCallback
{
public int callbackOrder => int.MaxValue;

public bool OnPreprocessAvatar(GameObject avatarGameObject)
{
if (Application.isPlaying)
{
foreach (var physBone in avatarGameObject.GetComponentsInChildren<VRCPhysBone>(true))
{
physBone.InitTransforms(true);
physBone.InitParameters();
}
}

return true;
}
}
}
3 changes: 3 additions & 0 deletions Editor/VRChat/ForceReinitPhysBonesHook.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f265254

Please sign in to comment.