Fix RebuildHumanAvatar so it works in play mode

This commit is contained in:
Ansis Māliņš 2026-01-08 21:20:35 +01:00
parent 3b99078d26
commit 3727eee600
2 changed files with 12 additions and 3 deletions

View File

@ -55,7 +55,10 @@ namespace UniHumanoid
/// HumanBone のマッピングを流用して、新たな Avatar を作り直す。
/// 古い Avatar は破棄する。
/// </summary>
public static void RebuildHumanAvatar(Animator animator)
/// <remarks>
/// This method runs asynchronously only in play mode.
/// </remarks>
public static async Awaitable RebuildHumanAvatar(Animator animator)
{
if (animator == null)
{
@ -77,6 +80,9 @@ namespace UniHumanoid
if (Application.isPlaying)
{
GameObject.Destroy(animator);
// Else, the following AddComponent call will fail.
await Awaitable.NextFrameAsync();
}
else
{

View File

@ -53,7 +53,10 @@ namespace VRM
/// <param name="go">対象モデルのルート</param>
/// <param name="forceTPose">強制的にT-Pose化するか</param>
/// <param name="useCurrentBlendShapeWeight">BlendShape の現状をbakeするか</param>
public static void Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
/// <remarks>
/// This method runs asynchronously only in play mode.
/// </remarks>
public static async Awaitable Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
{
if (forceTPose)
{
@ -83,7 +86,7 @@ namespace VRM
// 回転とスケールが除去された新しいヒエラルキーからAvatarを作る
if (go.TryGetComponent<Animator>(out var animator))
{
HumanoidLoader.RebuildHumanAvatar(animator);
await HumanoidLoader.RebuildHumanAvatar(animator);
}
}