Skip to content

Commit f265254

Browse files
committed
fix: workaround VRCSDK bug where stale data is left in physbone state
Closes: bdunderscore/modular-avatar#845
1 parent 5617be4 commit f265254

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#region
2+
3+
using UnityEngine;
4+
using VRC.SDK3.Dynamics.PhysBone.Components;
5+
using VRC.SDKBase.Editor.BuildPipeline;
6+
7+
#endregion
8+
9+
namespace nadena.dev.ndmf.VRChat
10+
{
11+
/// <summary>
12+
/// When domain reload is disabled, the VRChat physbones gizmo can leave outdated data in the VRCPhysBone component
13+
/// when entering play mode. Force reinitialize the components to work around this issue.
14+
///
15+
/// Note that we only do this when entering play mode, as this is runtime state, not serialized state.
16+
/// </summary>
17+
public class ForceReinitPhysBonesHook : IVRCSDKPreprocessAvatarCallback
18+
{
19+
public int callbackOrder => int.MaxValue;
20+
21+
public bool OnPreprocessAvatar(GameObject avatarGameObject)
22+
{
23+
if (Application.isPlaying)
24+
{
25+
foreach (var physBone in avatarGameObject.GetComponentsInChildren<VRCPhysBone>(true))
26+
{
27+
physBone.InitTransforms(true);
28+
physBone.InitParameters();
29+
}
30+
}
31+
32+
return true;
33+
}
34+
}
35+
}

Editor/VRChat/ForceReinitPhysBonesHook.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)