Restriction on downloaded AssetBundles?

Hello,

I got a problem with a special setup we want to deploy. We are developing a unity web application. As an alternative to the web player we want to deploy a standalone exe which streams the web assets due to technical reasons (blocked browser plugins @ schools for example).

However with the standalone exe when I try to LoadLevel() a scene from an assetbundle (downloaded from webserver) I get the error:

The class defined in script file named '...' does not match the file name!

When using the same code to LoadLevel() directly from a script on the webserver it works flawlessly.

The loading code:

	IEnumerator LoadAndStartLevel() {
		string url = "http://localhost/test/Login.unity3d";
		WWW www = new WWW(url);
		yield return www;
		www.assetBundle.LoadAll();
		Application.LoadLevel("Login");
	}

The export code for generating the scene files:

BuildPipeline.BuildPlayer(new string[]{"Assets/_Scenes/Login.unity"}, "Assets/AssetBundles/Login.unity3d", BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);

The error is unexpected because the scenes all run flawlessly when run directly and even when loaded directly from/to another script on the webserver. It just doesn’t seem to work when loaded by a standalone exe.

Any suggestions? Is this a security issue? What are the best practices available?

Haven’t found an answer to this one yet. Bump.

You sad

but then you are using:

BuildPipeline.BuildPlayer() with the option "  BuildTarget.WebPlayer

If you like to load the Asset Bundels on windows, you have to choose BuildTarget.StandaloneWindows.

Changing the BuildTarget has no effect on my results.

BuildPipeline.BuildPlayer(new string[]{"Assets/_Scenes/Login.unity"}, "Assets/AssetBundles/Login.unity3d", BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);

Gives me the same “class does not match file name” error when I WWW load it from a standalone exe or even the editor.

What is the name of the file witch he is complaining about in this error massage?

The class defined in script file named '...' does not match the file name!

And what is the name of the class you defining in that file?

Loader
Is a scene named “game.unity” with a script named “loader.cs” attached to the Main Camera. In Start() of the loader.cs the function LoadAndStartLevel() (see my first post) is called via StartCoroutine once.

WWW Asset
Is a scene named “Login.unity” with just a standard “Main Camera” and an empty GameObject with a script named “Login.cs”. The GameObject has just 3 texture2ds attached to it through public variables in the Login.cs. The script just shows GUI elements OnGUI() and does pretty much nothing else. There are no additional scripts attached.

The script named “Login.cs” is defined in code like this:

public class Login : MonoBehaviour {
...
}

The Loader works just fine. It does what it should do. But it just can’t start the Login scene in the exported Login.unity3D asset file.

Starting the Login scene by itself - directly - works flawlessly. So I am pretty sure there is no error in my scene but in my export or WWW load. But the error message I get is pretty misleading and gives me nothing to work with as a Unity newbie.

Answering to you actually made me answer my own question. Everything in the code AND the export is perfectly fine. Therefore I looked outside the box. It turns out that you can’t call an AssetBundle from different unity projects. The Loader “has to know” about the scripts in the loaded asset files. This is of course pretty bad as the whole purpose of loading scenes from the internet is pretty much useless if you cant update those scenes without breaking the loader.

Scenario:
Install the “loader” application at a customer. He runs it and everything works fine. Now you update the scenes bundles which li eon your web server because you found a bug. Now the loader application can’t load these assets anymore because he doesn’t know about the new class you needed to code to solve the bug.

Probable solution:
Code your own loader in visual studio / xcode / whatever. This loader will then download the newest unity executable file which was compiled and updated whenever any one scene in the unity project was changed so that it can load them. This of course is a bad approach because the unity executable files are GIGANTIC (9.5 mb or even more) in comparrison to the actual exported scene files(<500 kb).

Short answer:
You just can’t load an exported scene from one unity project to another. Or even the same project of a different code state. Even if the scenes are 100% self-contained and have nothing to do with another.