Manual loading scene inside editor

For loading scene inside editor I use this function:

Resources.LoadAssetAtPath("Assets/Scenes/myscene.unity", typeof(Object));

It returns me instance of UnityEngine.DefaultAsset

Then I try load “myscene” using this function:


But it says that
Level ‘myscene’ (-1) couldn’t be loaded because it has not been added to the build settings.

I don’t want to add it to build settings, because in web player I load it using bundles.
And inside editor I want to load it directly. How can I do it?

I think you are looking for this:



create a simple ‘if’ block with this check and load scene directly or using bundle. you can’t write in one line a code that will load asset bundle packed scene in unity web player or directly using editor’s methods if you are in editor.

also you can use #IF blocks to exclude editor-loading lines from web player build

with ur scene open. go to Files->BuildSettings then clic the Add Current button. and u r set to go