UniVRM icon indicating copy to clipboard operation
UniVRM copied to clipboard

[Reload Scene Only] Editorで再生・停止を繰り返すと、"_look_at_origin_"オブジェクトが無限に生成される

Open KichangKim opened this issue 7 months ago • 4 comments

環境情報

  • UniVRM version: 0.129.1
  • Unity version: Unity-6000.1.6f1
  • OS: Windows 11

バグについて

  • バグの内容
    • Enter Play Mode SettingsをReload Scene Onlyにした状態でVRMプレハブをシーンに配置し、EditorのPlay/Stopを繰り返すと毎回_look_at_origin_というオブジェクトが生成される
  • ConsoleLog
  • スクリーンショット Image
  • 再現方法
    • VRoid StudioでVRM 1.0形式に書き出し -> Unityシーンに配置後、Play/Stopを繰り返す。

KichangKim avatar Jun 15 '25 06:06 KichangKim

Reload Scene Only にする。

新しいシーンに ssed さんの prefab を配置。 Play / Stop を繰り返す。

再現させることができませんでした。

Image

6000.1.6f1, 6000.2.0f1, 6000.0.49f1

ousttrue avatar Aug 18 '25 11:08 ousttrue

再現条件をより絞った結果、ULipSyncExpressionVRMコンポーネントが原因でした。VRMプレハブをシーンに配置し、ULipSyncExpressionVRMコンポーネントを付け、blendshape設定を1個追加すると発生します。ULipSync側の不具合の可能性もありますが念のため共有します。

https://github.com/hecomi/uLipSync/blob/main/Assets/uLipSync/Samples/04.%20VRM/Runtime/uLipSyncExpressionVRM.cs

KichangKim avatar Aug 18 '25 23:08 KichangKim

一応なんとなくの原因と対策が分かりましたので共有です。

ULipSyncExpressionVRM.csにて、OnApplyBlendShapeがアプリケーション実行前にもかかわらず?vrm10Instance.Runtime.Expression.SetWeightの関数を呼び出すことによって下記エラーが発生していました。 おそらくこのタイミングで_look_at_origin_が生成されるのですが、エラーで正しく廃棄処理ができなかったように思えます。

Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead.
UnityEngine.Renderer:get_materials ()
UniVRM10.MaterialValueBindingMerger:InitializeMaterialMap (System.Collections.Generic.Dictionary`2<UniVRM10.ExpressionKey, UniVRM10.VRM10Expression>,UnityEngine.Transform,bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Expression/MaterialValueBindingMerger.cs:68)
UniVRM10.MaterialValueBindingMerger:.ctor (System.Collections.Generic.Dictionary`2<UniVRM10.ExpressionKey, UniVRM10.VRM10Expression>,UnityEngine.Transform,bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Expression/MaterialValueBindingMerger.cs:309)
UniVRM10.ExpressionMerger:.ctor (UniVRM10.VRM10ObjectExpression,UnityEngine.Transform,bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Expression/ExpressionMerger.cs:37)
UniVRM10.Vrm10RuntimeExpression:.ctor (UniVRM10.Vrm10Instance,UniVRM10.ILookAtEyeDirectionApplicable,bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Vrm10Runtime/Vrm10RuntimeExpression.cs:28)
UniVRM10.Vrm10Runtime:.ctor (UniVRM10.Vrm10Instance,bool,UniVRM10.IVrm10SpringBoneRuntime,System.Collections.Generic.IReadOnlyDictionary`2<UnityEngine.Transform, UniGLTF.Utils.TransformState>,bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:80)
UniVRM10.Vrm10Instance:MakeRuntime (bool) (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Vrm10Instance/Vrm10Instance.cs:148)
UniVRM10.Vrm10Instance:get_Runtime () (at ./Library/PackageCache/com.vrmc.vrm@813d949ebbd5/Runtime/Components/Vrm10Instance/Vrm10Instance.cs:158)
uLipSync.uLipSyncExpressionVRM:OnApplyBlendShapes () (at Assets/uLipSync/3.1.5/04. VRM/Runtime/uLipSyncExpressionVRM.cs:36)
uLipSync.uLipSyncBlendShape:LateUpdate () (at ./Library/PackageCache/com.hecomi.ulipsync@30efb0c84d08/Runtime/uLipSyncBlendShape.cs:82)

ですので対応として以下のようにエディタ上ではisPlaying以外ではスキップするようにすると解消いたしました。

    protected override void OnApplyBlendShapes()
    {
        // Editor停止時には実行しない(GameObjectの無限生成を防ぐ)
#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            return;
        }
#endif
        
        var vrm10Instance = GetComponent<Vrm10Instance>();
        if (!vrm10Instance || !vrm10Instance.Vrm) return;

        var clips = vrm10Instance.Vrm.Expression.Clips.ToArray();
        foreach (var bs in blendShapes)
        {
            var index = bs.index + 1;
            if (index < 0 || index >= clips.Length) continue;
            var clip = clips[index];
            var weight = bs.weight * bs.maxWeight * volume;
            var key = new ExpressionKey(clip.Preset, clip.Clip.name);
            vrm10Instance.Runtime.Expression.SetWeight(key, weight);
        }
    }

kony428 avatar Nov 10 '25 06:11 kony428

@kony428 上記の修正で_look_at_origin_の無限生成がなくなりました。共有ありがとうございます。

KichangKim avatar Nov 11 '25 23:11 KichangKim