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
1
Question by Ekta-Mehta-D · Sep 02, 2015 at 08:20 AM · unity 5assetbundletextasset

How to include script in Assets Bundle ?

hii all..

I want to load scripts in assets bundle which is component of the gameobject..

But i failed to load those scripts. I have read the documnets given : http://docs.unity3d.com/Manual/scriptsinassetbundles.html

I have tried this like :

  //www = WWW.LoadFromCacheOrDownload ("file://E:/HTML5 Testcase/New Unity Project/Resources.unity3d", 1);
         www = WWW.LoadFromCacheOrDownload ("localpath/sample.unity3d", 1);
         
         // Wait for download to complete
         yield return www;
 
         if(www.error != null)
         {
             Debug.Log(www.error);
             yield break;
         }
 
         if(www.error != null)
         {
             throw new UnityException("WWW download had an error : " + download.error);
         }
 
         // Load and retrieve the AssetBundle
         AssetBundle bundle1 = www.assetBundle;
         bundle1.LoadAllAssets();
 
         // Load the TextAsset object
         TextAsset txt = bundle1.LoadAsset("Assembly-CSharp.dll", typeof(TextAsset)) as TextAsset;
         Debug.Log ("Txt : " + txt);
 
         if( txt!= null )
         {
             // Load the assembly and get a type (class) from it
             var assembly = System.Reflection.Assembly.Load(txt.bytes);
             var type = assembly.GetType("MyClassDerivedFromMonoBehaviour");
             
             //Instantiate a GameObject and add a component with the loaded class
             GameObject go = new GameObject();
             go.AddComponent(type);
             Debug.Log("Loaded.. ");
         }

But txt is coming null.

What is the problem with this script. please help me guys.

Thanks.

Comment
Add comment · Show 1
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 Scribe · Sep 09, 2015 at 12:10 PM 0
Share

You need to make sure you delete the namespace that is created for the .dll before you build it into the package so that its contents ends up in the global namespace I believe! Otherwise it loads it and then can't find it :o

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ajaybhojani · Sep 08, 2015 at 08:13 AM

hello you can direct attach script to object then make asset bundle of it . when you are downloading that bundle in unity editor run but it will not display as component in unity editor.

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 Ekta-Mehta-D · Sep 08, 2015 at 08:28 AM 0
Share

That script is not working and its saying about compiler error.

avatar image
0

Answer by sodrix · Sep 08, 2015 at 08:44 AM

Hum You are using 'myCode.cs' or 'myCode.txt'? Your code have into code for execute? you can test to change 'txt!=null' to 'txt.Length>0'

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 Ekta-Mehta-D · Sep 09, 2015 at 06:08 AM 0
Share

but txt.Length is co$$anonymous$$g always 0.

avatar image
0

Answer by Vaibhav_77 · Mar 06, 2019 at 10:10 AM

Any Solution ?

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

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Build assetbundle successfully but cannot instantiate it 0 Answers

Assetsbundle in subfolder 0 Answers

Building Asset Bundles requires Unity Advanced for AndroidPlayer 1 Answer

why UnloadUnusedAssets doesn't unload a asset? 0 Answers

Unity 5 Asset Bundles - missing specific sprites from downloaded scene? 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