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 3126c4f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

### Changed

### Deprecated

### Removed

### Fixed
- Workaround VRCSDK bug where stale PhysBones state could be retained over play mode transitions (#231)

### Security

## [1.4.0] - [2024-03-27]

### Added
Expand Down
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

This comment has been minimized.

Copy link
@bdunderscore

bdunderscore May 7, 2024

Author Owner

Make internal

{
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 3126c4f

Please sign in to comment.