- Home /
Acessing Scripts in Assets folder using .dll
Hi, I am creating a dll file for my AI engine.But i would love to acess other script as well
Is it possible to acess a script (say "Player Health Script" in Standard Assets Folder) from a dll project (which is inseide Unity Plugin folder)
if so would anyone be kind enough to guide me to do this
Thanks
You should be able to do this using reflection, but I don't think it's a good solution. $$anonymous$$aybe you should use different approach ins$$anonymous$$d, e.g. events. Could you explain what is your goal?
Hi @ArkaneX I have a dll file that has all functions and classes that i can acess from other script for building AI's with different behaviors
I would like to access the event system and object pooling script
The event system contains all the info about player and the AI's friends
But since these two are found in Assets folder i cant acess them using dll
Is there a specific reason why you want to keep your project as a dll, and not as script files?
@Arkanex, for any medium to large project, loose script files aren't practical unless you have the patience of a saint. For example, load a reasonable battery of Asset Store code products into an empty project -- maybe Ultimate FPS, Scene $$anonymous$$anager, Sound $$anonymous$$anager Pro, AI Behaviours, cInput, and NGUI -- and see how long it takes to build. Not long in the grand scheme of the universe, I admit, but a real pain if you want to make tiny iterative changes to a single script and test them out quickly.
That said (and stepping off my soapbox :-) ), I totally agree with you that maybe a different solution would be better, such as providing an interface in the DLL that the DLL itself can reference, and writing implementations as loose scripts in Assets. Or even using Send$$anonymous$$essage() (itself a form of reflection) if it's not in a time-critical loop.
Regarding dll vs project - if you want to quickly test tiny iterative changes, then script files is the way to go. You have to build anyway, and additionally you need to copy the output dll to the destination location. Of course you can automate this, but I still prefer to do it the scripts way :)
EDIT: there was a short info related to the Send$$anonymous$$essage which I deleted as soon as I saw what I posted. You can of course use it in this case.
Answer by TonyLi · Jan 14, 2014 at 02:57 PM
Since the DLL is compiled without knowledge of the scripts in the Assets, you'll have to use reflection. Here's a good tutorial on using reflection.
Note that if you're building for iOS, you'll probably have to include a link.xml file so the scripts don't get stripped from the build.
wow thanks for the reply I never knew that refletion could come in handy here
Excuse me if my opinion is absurd, but wouldn´t it be enough to add a reference to UnityEngine and then program normally?
Right, but you could add a reference to UnityEngine.dll and do unity stuff, as long as you don´t call any of your own scripts. Depending on your situation I´d image this could be enough. Using reflection seems more powereful but also a lot more dangerous!
Even if he adds UnityEngine reference, he won't be able to see other script, because this dll won't even know about its existence.
Yes, but he can use transforms, rigidbodies, renderers, audio, cameras... $$anonymous$$ost useful compoenents are already built in so I thought it might be just enough.
Your answer
Follow this Question
Related Questions
OSC to Unity Messages 0 Answers
A node in a childnode? 1 Answer
Including a DLL in unity? 1 Answer
Cannot compile .exe with specific .dll. (but with other .dlls created the same way) 0 Answers