- Home /
Unable to stream Assetbundles from web...
Hello There,
I have been trying to stream assetbundles from the Web Server which I own on one of my machines. The site is served by Apache Server application.
I have written the below two very basic script to serve this purpose:
using UnityEngine; using System.Collections; using System.Collections.Generic;
//Model pair structure which is used to store a single string/WWW instance struct ModelPair{ public string url; public WWW link; };
public class ModelLoader: MonoBehaviour {
//Model Request Queue
Queue<ModelPair> queue;
//Models instantiated so far
ArrayList models;
//Awake Method
void Awake(){
queue = new Queue<ModelPair>();
models = new ArrayList();
}
//Fixed Update
void FixedUpdate(){
if( queue.Count > 0 ){
//1. Pick one item from the queue
ModelPair item = queue.Dequeue();
//Debug.Log( "Picked Item: " + item.url )
//2. Check if a WWW is instantiated for item
if( item.link != null ){
// 2.1 If yes check whether if there exists an error in streaming the file
if( item.link.error != null ){
// 2.1.1 If yes log an error message, pop the item and return
Debug.Log( item.link.error );
return;
}
// 2.2 Check whether the file is loaded
if( item.link.isDone ){
// 2.2.1 If yes, instantiate the loaded model insert it to the models array. Pop the item and return
GameObject model = (GameObject)Instantiate( item.link.assetBundle.mainAsset);
models.Add( model );
return;
}
else{
// 2.2.2 If no requeue the file at the end and return
queue.Enqueue( item );
}
}
else{
//3. If not create a new WWW instance for the item
item.link = new WWW( item.url );
queue.Enqueue( item );
return;
}
}
}
//request a model at a particular url location to be loaded by the model loader
//This function enqueues the request to the queue
public void request( string url ){
ModelPair newItem;
newItem.url = url;
newItem.link = null;
queue.Enqueue( newItem );
}
}
I have a second script which uses this one and makes a model request as follows
using UnityEngine; using System.Collections;
public class SceneObjectStreamer : MonoBehaviour {
//Model loader instance
public ModelLoader modelLoader;
//GUI
public SceneGUI gui;
// Use this for initialization
void Start () {
if( modelLoader != null ){
modelLoader.request("file:///D:/projects/AssetBundleSerialization/assetbundles/athena.unity3d");
}
}
}
The athena.unity3d is the assetbundle I have created correctly with my editor script. Anyway heres the problem. When I try to load this assetbundle from my file system it works correctly and the assetbundle pops up right away in the scene without problems.
However when I replace the URL with "http://www.mywebpage.com/athena.unity3d" I get an error which is:
Failed to load asset bundle UnityEngine.WWW:get_assetBundle() UnityEngine.WWW:get_assetBundle() ModelLoader:FixedUpdate() (at Assets\AssetBundleSerializationAssets\Scripts\Streaming\ModelLoader.cs:47)
Following this one I get a null pointer exception as the "mainAsset" field of the Assetbundle is null now. However this occurs within the "if" which controls whether if the download is finished. So if this is supposed to be a download error then shouldnt it be caught by the previous "if" which checks whether there was an error during streaming?
Can it be related to my Apache Server Configuration? Though I have uploaded my web player there as an html/unity3d file and I can access it on my browser without any problems. So I believe it is not the Apache Server which restricts access to those locations.
Anyone else had similar experience? Could you help?
Thanks a lot,
Ates Akaydin
Answer by Ates Akaydin · Jun 01, 2010 at 07:52 AM
Ok got it solved... Shame on me for asking this question without removing Apache basic login/password authorization.
Though I dont know still if I can bypass it via web form and sending it over via WWW instance before requesting the file.
IF anyone know of a secure way of transmitting files via WWW instance I would really appreciate that.
Best,
Ates