umasteeringgroup / UMA

Unity Multipurpose Avatar
MIT License
726 stars 167 forks source link

2.12 Prefab and Preview bug #356

Closed McGunn closed 3 years ago

McGunn commented 3 years ago

Describe the bug It is now impossible to use the UMA characters as part of a nested prefab. With the "Editor Time Generation" enabled it unpacks all parent prefabs in the scene, and with "Editor Time Generation" disabled the character is not compiled at runtime but instead a preview of the character is left in the T-pose at the position where the character started.

Environment (please complete the following information):

To Reproduce Steps to reproduce the behavior:

  1. Make a prefab
  2. Put the getting started DCA prefab into your new prefab as a nested prefab.
  3. Drag that prefab into the scene and notice the prefab unpack.
  4. Remove Prefab from the scene.
  5. Edit the DCA prefab so that it doesn't render a preview.
  6. Drag the prefab into the scene and now it likely won't unpack the parent, but if you mess around in the scene and play and stop and save eventually it will still unpack it.
  7. Hit play and see that the character is never compiled and that a T-pose preview is left in it's place.

Expected behavior At the very least for the no-preview version to work properly. At best a way to set up the preview so that it's friendly to being a nested prefab, or at least so that it throws an error rather than unpacking the prefab.

Additional context I rolled back to 2.11.6 release. And nested the DCA prefab with "Editor Time Generation" disabled. And everything works perfectly.

etonix commented 3 years ago

Unity Version: 2019.4.21f1 UMA Version: 2.12

Console log for this error finally showed up, but only after reverting to 2.11.6 (following McGunn's lead) and getting nowhere, removing UMA entirely, and reimporting 2.12.

This only occurs on code instantiated prefabs. Prefabs dragged into the scene in play mode, and prefabs that start with the scene are unaffected. I have turned off and on editor spawning, tried spawning the prefab with DCA disabled and then enabling, tried spawning an un-nested UMA prefab to the nested location - UMAData DNA sets to 'UMADnaBase' and this error churns without spawning a renderer object until I manually change the race in the editor.

InvalidCastException: Specified cast is not valid. UMA.UMAData+UMARecipe.EnsureAllDNAPresent () (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAData.cs:1261) UMA.UMAData+UMARecipe.PreApplyDNA (UMA.UMAData umaData, System.Boolean fixUpUMADnaToDynamicUMADna) (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAData.cs:1175) UMA.UMAData.PreApplyDNA () (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAData.cs:1547) UMA.UMAGeneratorBuiltin.PreApply (UMA.UMAData umaData) (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:573) UMA.UMAGeneratorBuiltin.GenerateSingleUMA (UMA.UMAData data, System.Boolean fireEvents) (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:300) UMA.UMAGeneratorBuiltin.OnDirtyUpdate () (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:454) UnityEngine.Debug:LogException(Exception) UMA.UMAGeneratorBuiltin:OnDirtyUpdate() (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:476) UMA.UMAGeneratorBuiltin:Work() (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:160) UMA.UMAGeneratorBuiltin:Update() (at Assets/UMA/Core/StandardAssets/UMA/Scripts/UMAGeneratorBuiltin.cs:112)

ColinCreamer commented 3 years ago

Unity Version: 2020.1.9.f1 Pipeline: URP Uma Version: 2.12

I am also experienceing this bug with prefabs varients. All prefab varient instances in the scene with uma on it become unpacked when Uma 2.10 is removed and replaced with 2.12. Additionaly, the master prefab inside of each of these prefab varients also becomes unpacked.

Stucture: Master Prefab > Many prefab variants

Jaimi commented 3 years ago

With "Edit time generation" enabled, we have to generate a skinned mesh renderer and all the bones. This causes an error unless the prefab is unpacked. If there is another way to do this so it doesn't need to be unpacked, I would be happy to look into it:

The unpacking happens here, in GenerateSingleUMA in DynamicCharacterAvatar.cs

                if (UnityEditor.PrefabUtility.IsPartOfPrefabInstance(gameObject.transform))
                {
                    // Unfortunately we must unpack the prefab or it will blow up.
                    GameObject go = PrefabUtility.GetOutermostPrefabInstanceRoot(this.gameObject);
                    UnityEditor.PrefabUtility.UnpackPrefabInstance(go, UnityEditor.PrefabUnpackMode.Completely, UnityEditor.InteractionMode.AutomatedAction);
                }

Perhaps this can be changed to PrefabUnpackMode.OutermostRoot?

Jaimi commented 3 years ago

@McGunn - there was a bug in 2.12 that was building (and unpacking) the DCA on scene save (to save scene space, all UMA's with edit time generation are cleaned up before the save, and regenerated after the save, otherwise the scene itself contains all the mesh data). This will be fixed in the next release.

Jaimi commented 3 years ago

In 2.13, The packing/unpacking is now a little less severe, and the scene save issue is fixed.