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 Ashkan_gc · Oct 14, 2010 at 07:56 AM · assetbundleassemblypatch

how can i put components in external dlls and store dlls in asset bundles

i want to store my components in assemblies that i define and then put them in asset bundles. in this way, new functionality can be added to games. complete patches are easily possible. so can i create a car mesh and a car.dll assembly and make an asset bundle of them and then download it from my game and use it with it's new scripts?

there is not any info about components in external assemblies nowhere. where should i put the dll? where should i put that for web players. where unity looks for external components. for example if i say

CarScript s = new CarScript();
this.gameObject.AddComponent(s);

this is not real code.

where unity looks for the component?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Ashkan_gc · Apr 03, 2011 at 01:18 PM

now it's possible to put components in dlls and use them. unity will recognize them in the editor. also i think from 3.2 we can add components from assemblies loaded in runtime as macfanpro answewred here. reflection is not needed anymore and you just need to use AddComponent with the type that is in the dll.

Comment
Add comment · Show 2 · 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 Ray-Pendergraph · Apr 03, 2011 at 07:41 PM 0
Share

Thanks for the update!

avatar image flberger · Jun 11, 2013 at 11:38 AM 0
Share

But where in the file system do I put the dll so Unity can find it?

avatar image
1

Answer by ckfinite · Apr 02, 2011 at 04:58 PM

This is a quite complicated question, for a couple of reasons. First, Unity was not really intended for run-time modification of behaviors from external sources, and as such, you cannot really use, for instance, MonoBehavior from a outside DLL. However, there is a way around this, and that is to use your own behaviour class that exposes the same virtual functions as MonoBehavior and load those using C# reflection from a external DLL.

What you could do is make a class like this:

public abstract class ExtBehavior {
    public virtual void Initialize()
    {
    }
    public virtual void Update()
    {
    }
}

Then extend it like this

public class TstBehaviour : ExtBehavior {
    public override void Initialize()
    {
    }
    public override Update()
    {
    }
}

You will need to put the external DLL containing ExtBehavior into Library/Frameworks, under the Unity folder. This is so the compiler can resolve the type of ExtBehavior.

Then load the behaviors like this

Assembly assem = Assembly.LoadFrom("nameOfDLL.dll");
IEnumerable<Type> behaviors =assem.GetTypes()
                .Where(type=>typeof(ExtBehavior).IsAssignableFrom(type));

Now, when you need a component, you just iterate through this array of Types until you find the one you need, construct it, cast it, then use it. I recommend creating a normal MonoBehavior that takes the name of the component that is loaded, as well as a Dictionary that takes parameters, then loads this dictionary into the external behavior through a protected constructor in ExtBehavior.

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

Answer by Ray-Pendergraph · Oct 14, 2010 at 01:05 PM

I won't say you can't store it but I think the problem is that how do you get the unadulterated DLL bits out of the bundle? We tried this with other binary formats and the rather ugly workaround was to Zip compress then Base64 encode the bits as a text asset. Bad, bad, bad... but it was right before the release. It blew the game size up like a balloon. If you could figure out a way to say "Get this blob as raw bits" you could load the DLL internally and use it with some C# trickery.

If you figure out how to do this with a DLL I would love to know... I'll update the community page.

Comment
Add comment · Show 3 · 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 Ashkan_gc · Oct 14, 2010 at 04:11 PM 0
Share

there is a good way to do that easily. you can use file reading system.IO of .net to read a encoded file (package of your pdfs) and then decode it and use it. for dlls, using reflection is possible but not as easy as i want.

avatar image Ray-Pendergraph · Oct 14, 2010 at 04:18 PM 0
Share

Sure you can read anything with System.IO but that gets tricky with a varying deployment base. What about web player, when will the content get installed to the drive?

avatar image Ashkan_gc · Apr 03, 2011 at 01:19 PM 0
Share

i just updated the answer with the up to date information.

avatar image
0

Answer by LtKelleyUSMC · Jan 13, 2013 at 01:33 AM

Hey there people, I have actually created an external DLL, and have it working with MonoDevelop, and Unity3D. Check out my video at http://www.youtube.com/watch?v=M4PoAc3XQKI&feature=youtu.be I will be creating a tutorial video on how to do this soon.

Comment
Add comment · Show 2 · 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 flberger · Jun 11, 2013 at 11:36 AM 0
Share

Please answer the question here in place, if at all possible.

avatar image Psyco92 · Feb 26, 2014 at 01:48 PM 0
Share

bump previous comment

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to move value in the inspector to script in the assetbundle 0 Answers

yield on WWW? or AssetBundleRequest? or both? 2 Answers

Dynamically loading scripts 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