microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Migration window does not properly check (and upgrade) dependencies #8694

Closed thalbern closed 9 months ago

thalbern commented 4 years ago

Describe the bug

Bug (or missing feature) on upgrading the following scenario:

In all scenarios the data / gameobject will be migrated but the result is going to be not as expected.

Scenario 1: Upgrading just the scene:

Expected result: we should after upgrading still conserve the original intend of having the component inherited from the prefab and only some values overridden.

Scenario 2: Upgrading just the prefab:

Expected result: On prefab upgrades the tool should automatically show all dependencies in all scenes and inform the user / give them a choice to upgrade the instances in those scenes as well so they're not loosing any data. The obsolete / deprecated component in the prefab can only be removed after successful upgrade/migration of all the instances/dependent game objects.

Note: consider several prefab hierarchies for this as well!

Scenario 3: Upgrading the whole project:

Can result in scenario 1 or 2 randomly depending on which file was found first by the tool.

thalbern commented 4 years ago

Throwing some code snippet here that might be useful for discovering the hierarchy of an instance that needs upgrading:

var boundingBox = gameObject.GetComponent<BoundingBox>();

            // we are based on one or more prefabs so we have to upgrade them first before upgrading our current gameobject
            Boo.Lang.List<PrefabInfo> prefabPaths = new Boo.Lang.List<PrefabInfo>();
            var rootPrefabInstance = boundingBox;
            while (HasPrefab(rootPrefabInstance))
            {
                BoundingBox prefabBox = PrefabUtility.GetCorrespondingObjectFromSource(rootPrefabInstance);
                string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(prefabBox);
                prefabPaths.Add(new PrefabInfo(prefabPath, prefabBox));
                rootPrefabInstance = prefabBox;
            }

            // update prefab hierarchy
            for (int i = prefabPaths.Count - 1; i >= 0; ++i)
            {
                GameObject prefabRoot = PrefabUtility.LoadPrefabContents(prefabPaths[i].path);
                MigrateStage(prefabPaths[i].box);
                UnityEditor.PrefabUtility.SaveAsPrefabAsset(prefabRoot, prefabPaths[i].path);
                PrefabUtility.UnloadPrefabContents(prefabRoot);
            }

            // update actual instance
            MigrateStage(boundingBox);

            // remove bounding box
            if (rootPrefabInstance != boundingBox && prefabPaths.Count != 0)
            {
                int rootIndex = prefabPaths.Count - 1;
                GameObject prefabRoot = PrefabUtility.LoadPrefabContents(prefabPaths[rootIndex].path);
                prefabPaths[rootIndex].box.enabled = false;
                UnityEditor.PrefabUtility.SaveAsPrefabAsset(prefabRoot, prefabPaths[rootIndex].path);
                PrefabUtility.UnloadPrefabContents(prefabRoot);
            }
            else
            {
                Object.DestroyImmediate(boundingBox);
            }
stale[bot] commented 2 years ago

This issue has been marked as stale by an automated process because it has not had any recent activity. It will be automatically closed in 30 days if no further activity occurs. If this is still an issue please add a new comment with more recent details and repro steps.

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visithttps://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!