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
0
Question by KaiserJohan · Mar 30, 2012 at 10:04 AM · c#

C# Reflection and Android/IOS

Hello,

Does Reflection truly work on Android/IOS? For example,

 Assembly testAssembly = Assembly.LoadFile("Test.dll");

Fails because it cannot find the file specified when I try run it on Android.

Thanks

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 Bunny83 · Mar 30, 2012 at 10:27 AM

I guess it should work According to the MonoCompatibility page. Assembly.Load() with a Byte array works even in the webplayer.

I guess your problem is where your file is located. Since you load it manually the file isn't part of your build so you have to copy it manually somewhere from which you can load it. You might want to use one of those directories: Application.dataPath, Application.persistentDataPath or Application.temporaryCachePath

Also keep in mind when you load assemblies with classes derived from MonoBehaviour or Scriptableobject you can't use them in Unity. The class for itself works, but AddComponent will fail since the class is unknown to the Assetdatabase of your project.

It works fine if you use only custom classes (not derived from MonoBehaviour).

Comment
Add comment · Show 4 · 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 KaiserJohan · Mar 30, 2012 at 11:28 AM 0
Share

Is there Really no way to include the dll when building an app in unity? Asking everyone to manually copy it to a destination on the phone is way too much of a hassle. It seems like quite a limitation, why would they not provide something like that?

avatar image Bunny83 · Mar 30, 2012 at 12:21 PM 0
Share

I was wondering why you actually want to load it manually :D

.NET / $$anonymous$$ono assemblies can just be dropped anywhere in the assets folder. In this case they are part of the project and can contain also classes derived from $$anonymous$$onoBehaviour.

All your scripts in your project are also compiled into a dll assembly. You never have to load an assembly manually when it's available at building time. You can use it like any other assembly.

A little sidenote: If your dll contains $$anonymous$$onoBehaviour components Unity will "extract" them into the global namespace. The dll-asset in your project view shows contained components ($$anonymous$$onoBehaviours) as sub assets so you can drag&drop them onto GameObjects.

avatar image KaiserJohan · Mar 30, 2012 at 01:24 PM 0
Share

I need to do this because I have pre-built in Visual Studio different DLL's depending on which platform. The DLLs are wrappers for native code on their platform For example, I have one built for PC, which loads PC-native code. Then I have one buitl for Android/iOS, which links against UnityEngine (which the prior must not) to deter$$anonymous$$e platform, then loads their native versions.

$$anonymous$$y hack now is to always have reference to both DLLs even though I am only building for one of the platforms. This creates unnecessary amount of code and as a nasty side-effect will fill my log when the application starts with tons of DLLimport errors

If I was able to load at runtime I could deter$$anonymous$$e which DLL to import depending platform

avatar image Bunny83 · Mar 30, 2012 at 03:07 PM 0
Share

Well, native code is a different story. Plugins (true native code dlls [pro / mobile only]) just have to be placed in the plugins folder and can be wrapped with a simple DllImport attribute.

To automatically exclude certain code use Platform Dependent Compilation

The DLLs have to be removed or added to the project manually. There's no way i know to exclude an assembly from a build that is placed in the assets folder.

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

A node in a childnode? 1 Answer

Distribute terrain in zones 3 Answers

C# - Reflection to invoke static method freezes unity 0 Answers

Multiple Cars not working 1 Answer

turn on off particle system 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