- Home /
EditorSceneManager.OpenScene fails after AssetDatabase.Refresh
Hello everyone, thank you in advance for reviewing my post!
I am using a custom editor menu button to import a package, containing a scene, then immediately attempting to open that scene... all in one operation. The scene is reported as not being found at the provided path. If I run the operation again (package is already imported at this point), the scene loads find. The path value remains the same in both instances.
Error: ArgumentException: Cannot open scene with path "Assets/Scenes/SceneNameHere.unity".
Code:
AssetDatabase.ImportPackage(path, false); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
Anything obvious I am missing? Do I need to "wait" for some async operation to finish, despite forcing it to be synchronous?
I also added a small hack between the asset refresh and scene load, but to no avail:
while(EditorApplication.isCompiling && EditorApplication.isUpdating) {}
Unity Version: 5.3.0.f4
System Info:
OS: Windows 8.1 Pro
Ram: 16 GB
System: 64-bit
Processor: Intel i7-4850HQ
If this question is still active: i would guess that it's because the while loop too still doesn't pass execution to Unity in the correct time frame by exiting early through the given conditions, so the changes are not applied yet. $$anonymous$$aybe Opening the scene with a real delay could help (there are some solutions, like an invisible executeInEditmode GameObject with an editorscript or this: http://docs.unity3d.com/ScriptReference/EditorApplication-delayCall.html to make that work in the editor)
Answer by Anh-Pham · Apr 19, 2016 at 07:13 AM
Although their documents say "the scenePath should be relative to the project folder. Like: "Assets/MyScenes/MyScene.unity". But you have to use the absolute path.
Your answer
Follow this Question
Related Questions
Why does asset import fail? 0 Answers
How to make a new path register in the AssetDatabase? 2 Answers
Accidentally overwritten scripts with imported package. 2 Answers
How to avoid JavaScript namespace pollution? 2 Answers
Package Import Log 1 Answer