• 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 Amy Nelson · May 07, 2010 at 06:11 PM · assetbundle

Can asset bundles contain scripts?

I have two projects. In the first, I am creating an asset bundle that contains a prefab with a script attached.

In the second, I want to load the previously created asset bundle, instantiate the prefab, and access methods in the script. Is t$$anonymous$$s possible?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Ray-Pendergraph · May 07, 2010 at 06:26 PM

It's my understanding that asset bundles do not contain executable code. That is what unity packages and .NET assemblies are for. Assemblies do not contain source code but if you have compiled .NET code that you want to re-use you can drop the assembly in the project and it will pick them up as long as there are no extraneous dependencies. T$$anonymous$$s answer is also reflected in the second post of t$$anonymous$$s thread. Another good thread on t$$anonymous$$s is here.

Comment
Add comment · Show 6 · 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 Amy Nelson · May 07, 2010 at 06:48 PM 0
Share

My first approach was to build a .dll and use reflection to reach the functions. The problem I've run into is that I want the .dll to communicate back and forth w/ the containing page via js. For js to send a message, though, it needs to reference the game object to which the script is attached. Nothing in the .dll can be a game object, however, b/c when you use reflection to create an instance of a class in your .dll, it calls new() and game objects cannot be created using new().

avatar image Ray-Pendergraph · May 07, 2010 at 07:20 PM 0
Share

What if you have scene graph 'place holder' objects that are in the application and the code you want to exec is in dll objects defined by an interface. Then the (non MonoBehaviour) implentations get somehow registered with the statically placed scene graph objects that are MonoBehaviours. The the static scene graph object would delegate the incoming call to the interface implementation (dll object) that is registered with it. You can create objects (with new, no reflection needed) from the dll. Would that work?

avatar image Amy Nelson · May 10, 2010 at 04:47 PM 0
Share

That's basically the approach I believe I'll have to use. From a design standpoint, though, I feel it's less than optimal b/c whenever the dll needs information from the page, via js, it has to call out to the MonoBehaviour wrapper which makes the js call, then returns the results to the dll which does some processing and then sends the results back to the wrapper which forwards it along to the game. So, there is some bouncing back and forth between the dll and the wrapper when ideally the dll should just communicate directly w/ the page.

avatar image grimmy · Jan 27, 2012 at 05:35 PM 0
Share

Maybe I've got the wrong end of the stick here but I really don't understand this answer. In my project I have lots of asset bundles with scripts attached which download & run perfectly well. I can also access their script vars no problem. To do this I am just saving my asset bundles online (or locally) and downloading them from there. Simple.

avatar image rabbitfang · Jan 27, 2012 at 08:52 PM 0
Share

@grimmy, put simply (and from what I understand), all scripts are compiled into one file that is saved with the executable distribution.

The question asks if brand new scripts can be compiled and saved with AssetBundles, to which the answer is no (with the exception of using reflection which is complicated).

When you attach scripts to game objects that are packaged in AssetBundles (the game objects in bundles, not scripts), only a reference to the script is saved in the AssetBundles, not the scripts themselves.

Show more comments
avatar image
0

Answer by theBrandonWu · Jul 05, 2013 at 06:56 PM

Just for reference from the Unity documentation:

Including scripts in AssetBundles http://docs.unity3d.com/Documentation/Manual/scriptsinassetbundles.html

Comment
Add comment · Show 1 · 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 hollym16 · Aug 05, 2014 at 03:52 PM 0
Share

Is it possible to have a script in the main project that references objects within the AssetBundle? I've used GameObject.Find("pathway"); but it doesn't seem to work. Anyone have any ideas?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to import the object from server to unity 2 Answers

Load 3D model from external drive in runtime without using Assetbundle ? 1 Answer

How to auto find a component inside an assembly (dll)? 0 Answers

Load scene with navmesh from asset bundle 1 Answer

apply texture on OBJ files automatically in batchmode 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