Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiate() on existing VRM does not create InitialTransformStates correctly #2289

Open
negatron99 opened this issue May 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@negatron99
Copy link

negatron99 commented May 14, 2024

Environments (please complete the following information):

  • UniVRM version: 0.121.0
  • Unity version: Unity-2023.2.0b8
  • OS: Windows 11

Describe the bug

Hi,

I'm having problems with the springs on an imported VRM1.0 file.

The process in which I'm doing it is two-fold.

  1. Load the model, and store it, disabled, in the scene, inside a "modelCache" parent
  2. At a later time (user-initiated) the model is duplicated, the copy made visible and placed in the scene.

From the first step, the model appears to be loading fine. Not disabling it and just letting it show, and it works fine.

However, when using Instantiate to create a copy, the springs appear to be causing the hair to go up violently.

This does not occur on VRM0 files that have been migrated, a VRM0 file seems to duplicate correctly.

A basic example of it failing is

        private async void Start() {
            var instanceTask = Vrm10.LoadPathAsync(filename,
                awaitCaller: new RuntimeOnlyAwaitCaller()
            );

            while (!instanceTask.IsCompleted)
            {
                await Awaitable.EndOfFrameAsync();
            }

            var instance = instanceTask.Result;
            
            instance.gameObject.SetActive(false);

            var duplicate = Instantiate(instance.gameObject);
            
            duplicate.SetActive(true);
        }

As it's loading correctly in the first instance, I am wondering if there's any other procedures I need to follow after creating a duplicate of the loaded VRM? Any re-initialisation that isn't performed when just copy it?

Things I've tried, but didn't work

  1. Not disabling the cached version, it loads fine, the duplicate still doesn't work correctly
  2. Calling ReconstructSpringBone in multiple places after both the cached version and copy are created

Edit:

There are warnings in the console

J_Sec_Hair1_11 does not exist on load.
UnityEngine.Debug:LogWarning (object)
UniVRM10.Vrm10Runtime:GetOrAddDefaultTransformState (UnityEngine.Transform) (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:165)

UniVRM10.Vrm10Runtime:<CreateFastSpringBoneBuffer>b__31_3 (UniVRM10.VRM10SpringBoneJoint) (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:141)

System.Linq.Enumerable:ToArray<UniVRM10.FastSpringBones.System.FastSpringBoneJoint> (System.Collections.Generic.IEnumerable`1<UniVRM10.FastSpringBones.System.FastSpringBoneJoint>)
UniVRM10.Vrm10Runtime:<CreateFastSpringBoneBuffer>b__31_0 (UniVRM10.Vrm10InstanceSpringBone/Spring) (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:124)

System.Linq.Enumerable:ToArray<UniVRM10.FastSpringBones.System.FastSpringBoneSpring> (System.Collections.Generic.IEnumerable`1<UniVRM10.FastSpringBones.System.FastSpringBoneSpring>)
UniVRM10.Vrm10Runtime:CreateFastSpringBoneBuffer (UniVRM10.Vrm10InstanceSpringBone) (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:123)

UniVRM10.Vrm10Runtime:.ctor (UniVRM10.Vrm10Instance,bool) (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs:95)

UniVRM10.Vrm10Instance:Reinit () (at Assets/Plugins/UniVRM/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs:109)

model.runtime.TestDuplicating/<Start>d__2:MoveNext () (at Assets/scripts/model/runtime/TestDuplicating.cs:44)

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

lots of warnings of the same type.

@negatron99 negatron99 added the bug Something isn't working label May 14, 2024
@negatron99
Copy link
Author

I have downloaded the code and run some more tests on it

When creating the initial "cached" version, it adds a RuntimeGltfInstance

When copying, the Vrm10Runtime constructor uses the gltfInstance to determine "m_defaultTransformStates" (lines 76-89: Vrm10Runtime.cs)

However, the gltfInstance.InitialTransformStates is empty.

Hacking the code a little, if I force it to reinitialise the states from the model instead, the duplicated instance works correctly.

Putting a check if the gltfInstance.InitialTransformStates actually has something in there, if not it'll build them from the object as though the gltfInstance is null.

@negatron99 negatron99 changed the title Duplicated VRM1 springbones not working correctly Instantiate() on existing VRM does not create InitialTransformStates correctly May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant