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 Okais007 · Dec 28, 2018 at 01:43 PM · assetbundlescript loadingmodding

Dynamic DLL + AssetBundle prefab missing component error.

AssetBundle cannot load a Monobehavior from DLL Unityccccc[2018.3.0f2]


Hi everyone, this is the first time I ask a question on this forum, english is not my native language so please, be indulgent.

I am trying to make a game that has Mod support. This means that users can create their own assets and their own scripts.

To create assets they can make an AssetBundle witch is pretty simple to do. To make their own scripts it is pretty hard however.


The way I see it, you do the scripting part with 2 differents approaches:

The First one is to have a scripting system as text file and load them inside your game objects like Moonsharp(Lua) or IronPython(Python). Your scripts will probably be imported as text assets inside your assets bundle.

The Second one is to dynimically load DLL files inside your game and execute a function to enable your custom classes.

I went with the second approach.


Everything works fine if my DLL are inside my Asset forlder.

If I remove the DLL from the asset folder however I have to load them using AddAssemblyToDomain

     static byte[] loadFile(string filename)
     {
         FileStream fs = new FileStream(filename, FileMode.Open);
         byte[] buffer = new byte[(int)fs.Length];
         fs.Read(buffer, 0, buffer.Length);
         fs.Close();
 
         return buffer;
     }
 
     Assembly AddAssemblyToDomain(string AssemblyPath)
     {
         byte[] rawAssembly = loadFile(AssemblyPath);
         return AppDomain.CurrentDomain.Load(rawAssembly);
     }



When I use AddAssemblyToDomain, the Classes and symbols inside my custom DLL are correcly loaded. I can find classes / functions inside this DLL and execute them correcly:


 Type Loadertype = Array.Find(DynamicPlugin.GetTypes(), x => x.Name == "CustomPlugin");
         Debug.Log("Type = {" + Loadertype.Name + "}");
 
         var c = Activator.CreateInstance(Loadertype);
         var method = Loadertype.GetMethod("AlternativeInitialize");
         method.Invoke(c, new object[] { });



however, when I load a Prefab inside an AssetBundle with a MonoBehavior from that DLL, the monobehaviour component is referencing a missing script for some reason :


alt text


The Weird thing is that I can get add the component manualy to that gameObject.


alt text


I am wondering why my asset bundle cannot get the monobehaviour from the DLL correcly despite the fact that I can dynamically and manually do it myself at runtime.

I can call AddComponent function but it will be painfull when loading prefabs or entire scenes!

Source code is provided here: https://github.com/MalisPierre/DynamicDLL

Scenario explenation provided here: https://github.com/MalisPierre/DynamicDLL/wiki

Thank you and have anice day!

missingscript.png (31.5 kB)
addedscript.png (38.7 kB)
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
0

Answer by joaoborks · May 27, 2019 at 06:31 PM

Did you manage to make it work @Okais007 ? I'm interested

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

99 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 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 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 avatar image avatar image avatar image

Related Questions

How can I load in assets for a users mod? 0 Answers

Release additional content using AssetBundles? 1 Answer

Loading scene with scripts from asset bundle 1 Answer

How to import the object from server to unity 2 Answers

assets bundle for ios 4 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