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 rhylvin2016 · Jul 14, 2016 at 08:55 AM · assetbundlenullreferenceexceptionassemblytextassetbinary

BadImageFormatException: Include Script using AssetBundle

Hi, I wanted to create a feature where we could import scripts I found this Unity Documentation that let us include scripts on an AssetBundle https://docs.unity3d.com/Manual/scriptsinassetbundles.html

-I've edited this much so that it will search my files not web.

-The DebugTest.txt is a c# script that I wanted to import in. its just a Debug.Log() script on an Update to see if its working.

-Had to change bundle.Load into bundle.LoadAsset because Unity says it deprecated.

-At first I got an error called NullReferenceException which means there is nothing inside this line of codes:

 TextAsset txt = bundle.LoadAsset("debugTest", typeof(TextAsset)) as TextAsset;

that's why I had to put an if statement to see if txt is not empty. which is now isn't so Debug.Log ("txt has something inside"); is working. and so along with the log message. I got the error BadImageFormatException. which probably means. I'm in the right track? probably? cause it didn't have any compiler error, but starting the game does.

-BadImageFormatException doesn't give me a line of code error meaning when I click the console to see the line code error.. nothing happens. so what I did is put Debug.Log at each and every line of codes after loading the textasset object. It worked and in the console it wen't up to 1 and then the BadImageFormatException error which means the problem is assembly loading? maybe its deprecated?

this my simple script copied from the Unity Documentation.

 using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  
  public class ScriptImporter : MonoBehaviour {
      string url ="file:///C:\\Users\\rhylvin2016\\Documents\\ScriptImporter Trial\\Assets\\AssetScripts\\script";
      IEnumerator Start ()
      {
          while (!Caching.ready)
              yield return null;
  
          // Start a download of the given URL
          WWW www = WWW.LoadFromCacheOrDownload (url, 1);
  
          // Wait for download to complete
          yield return www;
  
          // Load and retrieve the AssetBundle
          AssetBundle bundle = www.assetBundle;
  
          // Load the TextAsset object
          TextAsset txt = bundle.LoadAsset("debugTest", typeof(TextAsset)) as TextAsset;
          if (txt != null)
     {
         Debug.Log ("txt has something inside");
     }
                      Debug.Log ("1");
          // Load the assembly and get a type (class) from it             
          var assembly = System.Reflection.Assembly.Load(txt.bytes);
                      Debug.Log ("2");
          var type = assembly.GetType("DebugTrial");
                      Debug.Log ("3");
          // Instantiate a GameObject and add a component with the loaded class
          GameObject go = new GameObject();
          go.AddComponent(type);
      }
  
  
  }








Comment
Add comment · Show 2
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 rhylvin2016 · Jul 14, 2016 at 04:53 AM 0
Share

@jdean300 @$$anonymous$$ischa @AngryAnt

avatar image LostDaemon · May 23, 2017 at 04:24 PM 0
Share

Hi, Did you resolve your issue? I faced with the same problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LostDaemon · May 25, 2017 at 02:56 PM

Hi, Did you resolve your issue? I faced with the same problem.

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

Script Import AssetBundle: ClassDerivedFromMonoBehaviour? 2 Answers

Load binary files from Resources 1 Answer

Runtime loaded assemblies 1 Answer

How to import the object from server to unity 2 Answers

in Unity 5, how can I get/set an asset's AssetBundle assignment via scripting? 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