Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jasminetay · Dec 01, 2015 at 02:38 PM · assetbundledownloadload sceneurl

Loading scene from assetbundle (url)

I want to load the scene using www but it fails to download and shows a null. I'm not sure why it doesn't download.

 using UnityEngine;
 using System.Collections;
 using AssetBundles;
 
 
 public class loadingscene : MonoBehaviour
 {
     public string sceneAssetBundle;
     public string sceneName;
     public string url;
     
     // Use this for initialization
     IEnumerator Start ()
     {    
         yield return StartCoroutine(Initialize() );
         
         // Load level.
         yield return StartCoroutine(InitializeLevelAsync (sceneName, true) );
     }
     
     // Initialize the downloading url and AssetBundleManifest object.
     protected IEnumerator Initialize()
     {
         // Don't destroy this gameObject as we depend on it to run the loading script.
         DontDestroyOnLoad(gameObject);
         // With this code, when in-editor or using a development builds: Always use the AssetBundle Server
         // (This is very dependent on the production workflow of the project. 
         //     Another approach would be to make this configurable in the standalone player.)
         #if DEVELOPMENT_BUILD || UNITY_EDITOR
         AssetBundleManager.SetSourceAssetBundleURL(url);
         //    AssetBundleManager.SetDevelopmentAssetBundleServer ();
         #else
         // Use the following code if AssetBundles are embedded in the project for example via StreamingAssets folder etc:
         AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
         // Or customize the URL based on your deployment or configuration
         /AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");
         #endif
         
         // Initialize AssetBundleManifest which loads the AssetBundleManifest object.
         var request = AssetBundleManager.Initialize();
         
         if (request != null)
             yield return StartCoroutine(request);
     }
     
     protected IEnumerator InitializeLevelAsync (string levelName, bool isAdditive)
     {
         WWW www = WWW.LoadFromCacheOrDownload (url, 1);
         yield return www;
         if (www.error != null) {
             print ("WWW donwload had an error : " + url + " " + www.error);
                 //Debug.Log("");
             }
         AssetBundle bundle = www.assetBundle;
         Debug.Log(www.assetBundle.mainAsset);
 
         // This is simply to get the elapsed time for this phase of AssetLoading.
         float startTime = Time.realtimeSinceStartup;
         
         // Load level from assetBundle.
         AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);
         if (request == null)
             yield break;
         yield return StartCoroutine(request);
         // Calculate and display the elapsed time.
         float elapsedTime = Time.realtimeSinceStartup - startTime;
         Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds" );
         bundle.Unload(false);
         // Frees the memory from the web stream
         www.Dispose();
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by David-Berger · Dec 02, 2015 at 10:04 AM

If you want to "download" the asset Bundle from the StreamingAssets folder you need to change

 AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

to something like

 AssetBundleManager.SetSourceAssetBundleURL(Application.streamingAssetsPath+"/");

More infos are here, here and here.

However if you want to download the Asset Bundles from the web you need to remove the / from line 36 of your posted code.

 /AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");

to

 AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");

Adapt the link and comment out the local call

 AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

before, otherwise it looks up the local path instead of the url.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Float to Integer 1 Answer

Error when downloading AssetBundle from external server during runtime 0 Answers

Unity 5 Download AssetBundles from server via URL. 2 Answers

Android: Additional data download 0 Answers

Alternative to BuildStreamedSceneAssetBundle ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges