Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by Stanislav Pugach · Aug 25, 2010 at 02:19 PM · assetbundlepluginscene-loading

Can a plugin-like system be implemented using AssetBundles?

The original plan was to have a "master" Unity project that would load asset bundles as plugins. For example, the master project would contain the main menu, and the bundles would contain levels, implemented as separate scenes.

That way, adding new levels would not require rebuilding of the player. Simply create the new level in a new scene, pack it into an asset bundle, and put it on the web in a predetermined location (and possibly mention it in some sort of online table of contents). The next run of the master player picks it up and voila - a new level is available.

It seems that this plan folds due to the inability of the bundles to contain code OR scenes, as after playing with asset bundles for a while, I stumbled upon the following error diagnostic: "Asset bundles can not include Scenes".

So the question is, basically, how, if at all? That is, can anyone suggest a mode of operation that would mimic the behaviour described above?

It is highly desirable that the plugins are developed separately from the main player. It is also imperative, obviously, for the resulting scene (as it appears within the master player) to contain some scripts (I am aware of the "Hydra workaround", but perhaps there is a better way?).

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
4
Best Answer

Answer by equalsequals · Aug 25, 2010 at 02:58 PM

Any Unity Web Player game I have worked on used separate Scenes as "Asset Bundles" so that the load time was broken up on a per-level basis.

Code to package a scene is here:

    _levels[0] = "Assets/Scenes/[Name of Scene].unity";
BuildPipeline.BuildPlayer(_levels, "Build/[Name of Bundle].unity3d", BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
if (System.IO.File.Exists("Build/[Name of Bundle].html"))
System.IO.File.Delete("Build/[Name of Bundle].html");

That is the hard-coded way of doing it, just place that in an Editor script and fire away.

A little setup is involved beforehand though. We have a folder next to our Assets folder in our Unity Project called Build (which is mentioned in the code above) as where the Bundles are stored.

Here is some code for loading the Bundle:

public AssetBundle loadedAsset;

 public void LoadAsset(string assetName)
 {
     StartCoroutine(LoadAssetHelper(assetName));
 }

 private IEnumerator LoadAssetHelper(string assetName)
 {
     //because our editor and web paths are different        
     if (Application.isEditor)
     {
         assetPath = "file://" + Application.dataPath + "/../Build/" + assetName + ".unity3d";
     }
     else
     {
         assetPath = Application.dataPath + "/" + assetName + ".unity3d";
     }

     www = new WWW(assetPath);

     yield return www;

     loadedAsset = www.assetBundle;
     //good place to place a callback

 }

Note: You may need to do some playing around with Application.dataPath in the precursor.

[Edit]

After reading your last comment I got curious as to why it wasn't working for you - so I just put together a quick project with 2 scenes that uses my method. Download the zip here.

You will see when you run the project that Scene1 contains several assets that MainMenu does not, they are all packaged in the bundle and run just fine on load. See the Build folder inside the project for an already working web player publish.

Hope that helps.

==

Comment
Add comment · Show 13 · 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
avatar image Stanislav Pugach · Aug 26, 2010 at 06:37 AM 0
Share

Interesting. How does one load these scenes? The only way I can think of is redirecting the browser to a new page. That, however, eli$$anonymous$$ates the possibility of using persistent scene objects to track global progress etc.

avatar image equalsequals · Aug 26, 2010 at 01:35 PM 0
Share

The second code sample is how you load the Scene via Asset Bundle into memory, from there it is business as usual for loading scenes just as if they were in the build settings: Application.LoadLevel("Scene Name"); Note: This is the Scene name, not the name of the Bundle's file if they were named differently.

avatar image Stanislav Pugach · Aug 27, 2010 at 04:58 AM 0
Share

Thanks, I already found that. There is a special word for these occasions: RTF$$anonymous$$ :-)

avatar image Stanislav Pugach · Aug 27, 2010 at 08:53 AM 0
Share

Tried this solution. It doesn't work for the following reason: the created "player" contains only the scene, but not the assets. So if I introduced a new asset, e.g. a material or, more importantly, a script, then it will not be available in the loaded scene.

avatar image equalsequals · Aug 27, 2010 at 01:27 PM 0
Share

That's not true, actually. Our scenes have several scripts and assets that are not included in the base scene. Perhaps there is something missing in my explanation that you need to do in the precursor.

Show more comments

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

No one has followed this question yet.

Related Questions

How to Load a scene from addressable on the preloading scene without changing scenes?,How do I preload an addressable scene without changing the scene? 2 Answers

AssetBundle Scenes 1 Answer

Can you use an asset bundle to replace an existing scene? 1 Answer

Scene assets not bundled in asset bundle 0 Answers

How to load a scene from an asset bundle in unity 5? 1 Answer


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