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
5.99k stars 2.12k forks source link

If Toolkit is moved to a new folder under assets, example scenes cannot locate files as needed #6448

Closed kelsosharp closed 4 years ago

kelsosharp commented 4 years ago

Run the Scene Hub project

I moved all of the MRTK assets imported into the project to a new folder called MRTK, when trying to run the ExampleSceneHub in the Unity player, it cannot locate the files, its looking in the assets folder.

To reproduce

Steps to reproduce the behavior:

  1. Create a new project
  2. import MR toolkit into assets folder
  3. Create new Folder under assets
  4. Select and drag MR toolkit folders into the new folder
  5. reimport all assets
  6. load ExampleSceneHub.unity
  7. Click Play in the Unity editor
  8. See Errors in Console.

Expected behavior

Should be able to locate examples based on the folder structure in the project.

Screenshots

UnityConsoleErrors

If applicable, add screenshots to help explain your problem.

Your Setup (please complete the following information)

Target Platform (please complete the following information)

iOS

wiwei commented 4 years ago

Thanks for filing this issue! So I've looked into a few of these types of issues in the past where most were caused by some random code that was hardcoding some paths (or otherwise searching in the root location instead of using the MixedRealityToolkitFiles abstraction).

This looks like another case - it looks like some of the newly added scene system stuff uses hardcoded paths in its serialized properties, instead of storing the guid of the asset instead (which is durable to file moves).

grep -ri Assets.MixedRealityToolkit --include=*unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHub.unity: Path: Assets/MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHub.unity: value: Assets/MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/UX/Tooltips/Scenes/TooltipExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/HandTracking/Scenes/HandMenuExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/HandTracking/Scenes/HandInteractionExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/EyeTracking/Scenes/EyeTrackingDemo-04-TargetPositioning.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/EyeTracking/Scenes/EyeTrackingDemo-03-Navigation.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/EyeTracking/Scenes/EyeTrackingDemo-02-TargetSelection.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/UX/Slate/SlateExample.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/UX/PressableButton/Scenes/PressableButtonExample.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/StandardShader/Scenes/ClippingExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/UX/Slider/Scenes/SliderExample.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/UX/BoundingBox/Scenes/BoundingBoxExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/EyeTracking/Scenes/EyeTrackingDemo-05-Visualizer.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/HandTracking/Scenes/NearMenuExamples.unity MixedRealityToolkit.Examples/Experimental/ExamplesHub/Scenes/MRTKExamplesHubMainMenu.unity: value: Assets/MixedRealityToolkit.Examples/Demos/StandardShader/Scenes/MaterialGallery.unity

For all of the things grepped above, none of these should be referencing paths directly and should be using GUIDs instead.

I'm going to add some tooling that will detect hardcoded paths that get checked in the future so that we don't keep letting these sorts of errors into the code.

@Railboy can you fix the scene related hardcoded paths here?

Railboy commented 4 years ago

For all of the things grepped above, none of these should be referencing paths directly and should be using GUIDs instead.

@wiwei Unfortunately it's not so straightforward. The SceneInfo struct holds a GUID, a name and a path. The GUID is for an editor-only asset (SceneAssetReference) which is stored as a unity object. The path is used to load the scene in the editor. The name is used to load the scene at runtime.

Related issues: #6060 Related PR: #6273

wiwei commented 4 years ago

@Railboy thanks for clarifying - my analysis there was wrong and as you say, the issue at hand was a lot more complicated than simply doing a GUID/path switch (there are runtime vs edit time considerations that aren't obvious because of Unity SceneManager interactions)