- Home /
How to rereference Monoscripts In Assemblies to Assetbundles
Assemblies can now contain Monobehaviour! Thats great! So what I'll like to do is the stream in Assetbundles with prefabs and assemblies containing monobehaviour scripts for the respective prefabs. The reason being we want to delegate different modules of a game to different people. Its also alot neater. And the final but most important reason is we're hoping to not have to rebuild the main scene (or any other completed scenes) over and over again while introducing new logic or modules to the game.
So far this is what I've tried:
- I stream in a scene with the assetbundle. (Nothing happens)
Then I copy and paste the dlls for the prefabs into any part of the "Assets" folder, held by a "Plugins" folder. POP! all the monoscripts suddenly get rereferenced and everything works fine!
I try to build the project.
- In the build project i stream in the assetbundle.
Then i try to dynamically load the DLL in script with AngryAnt's blog (nothing happens) (Oh the interesting part is upoon downloading the assembly, i tried to involke a method to print a statment and it works fine! =) Seems like the only remaining problem I have is the referencing of the scripts correctly which can be magically done right in editor mode but not during an executable's runtime... )
In my desperation I tried to just copy and paste the dll into the "managed" folder but nothing happens also.
Anyone with any thoughts on how to proceed from here on?
I think we're only missing a little referencing portion before monobehaviours can be streamed live from any URLs.
I also just noticed that then i do "AddComponent()" to the gameObjects after dynamically srea$$anonymous$$g the dlls at runtime, the attached scripts have no name =) This probably caused the dereferencing.
Oh and i also get the "Class defined in script file name 'myScript' does not have a file name!" error co$$anonymous$$g out on my console
Please help vote for this: http://feedback.unity3d.com/forums/15792-unity/suggestions/1324909-scripts-inside-assetbundles
Answer by denewbie · May 16, 2011 at 03:30 AM
Hi all, I've somewhat created a work around framework using hydra. Its a little complicated and quite a bit of work but if anyone's interested here's how it goes in a super nutshell:
.1. Built my owh little frame work layer on top of the monobahaviour. This is to control basic set-up stuff on each script. Then compiled everything into a .dll (I've found that not only can unity take in monobehaviour in their dlls, they can even be put in namespaces =) )
.2. Created what i call and "Orchestrator" script.
This is an important script that is in control of all incoming sub modules. It loads asemblies and set-up prefabs for its particular module. Foreach loaded module, I'll have an extended of this orchestrator and call it "WidgetOrchestrator". We only need 1 of each of these classes.
.3. Build my main module and include a "MainOrchestrator" script.
This is the boss controlling all of whats coming in. It currently pools the website for available modules and displays them for all to see. This is important and super cause by pooling whats available means we no longer need to internally change the codes of the main programming to include how to both realise the existance of now modules and use them.
.4. Create the web-server as mentioned above to pool data and download the assemblies and assetbundles.
////////////////////////////////
Those are the few critial steps in a nut shell. The DISADVANTAGES of this are can be pretty compelling: i. I feel that it breaks the idea flow of how unity supposed to be used especially the ability to attach scripts just by dragging and dropping (However, this was our problem in the first place. These scripts we dragged in just didnt work when we want them to dynamically load them).
ii. This idea is pretty complicated and its harder to check for bugs when theres some kind of error.
iii. The set up and deployment can be quite a hassle. You need to build an asstbundle, an assembly, write up meta files, build up your server (But then again even if scripts could be directly attached we still had to do all these anyway).
iv. An additional learning curve on how to proceedurally do things based on the framework you or I have designed to handle this.
The ADVANTAGES of this
i. Dynamic loading of now modules, logic and everythign which is what we've all been looking for.
ii. Never ever needing to rebuild your main project again.
iii. Able to divide work in a team to members can idependently work on their modules with a "sandbox" scene.
iv. Direct and immediate version upgrading since all data is directly pooled in from the web server.
v. No Down time to server and applications!
I know the steps above are like super vague so if any one is really interested i'm willing to share some of my codes with you all. Just comment me for them. Also, i thik it ll still be better for the all of us of the bundles could just contain the scripts and load them right so I'm still really open to better answers for this.
Hi,
I am interested in trying your solution. Is it possible to get sample code?
Thanks!
I want to know if it works with web players? and also how do you store references really?
Answer by Ashkan_gc · May 18, 2011 at 03:14 AM
angryant's solution is old and was good in those times that we could not have components in dlls. now you can put your monobehaviour in a dll and download it at runtime and then load it as an assembly in your code and then just use AddComponent without any additional framework/script. use Assembly.LoadFrom to load your assembly at runtime and then use addComponent. it's much easier.
Can you provide more detail on this please? I saw this mentioned in the question like this you posted yourself, and I'm still lost on exactly what to do. The 3-4 different ways to do it are confusing me when I try to research how to complete each step you mention.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133404im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Export objects to a .3DS file at runtime 1 Answer
References and Namespaces 0 Answers
Set Reflected assembly name after dynamically Loading Dll 0 Answers
GameObject references runtime script in scene file. Unsure whats wrong 2 Answers
Unity/C# Added assembelies, MonoDevelop builds, Unity won't run 0 Answers