I’ve read the documentation of AssetBundles, also the documentation about adding scripts in assetbundles.

the problem is I don’t even know how to start.

“AssetBundles can contain scripts as TextAssets but as such they will not be actual executable code. If you want to include code in your AssetBundles that can be executed in your application it needs to be pre-compiled into an assembly and loaded using the Mono Reflection class (Note: Reflection is not available on platforms that use AOT compilation, such as iOS). You can create your assemblies in any normal C# IDE (e.g. Monodevelop, Visual Studio) or any text editor using the mono/.net compilers.”

first of all how do we pre-compile into an assemby a script?

did anyone ever tried this? can anyone tell me how you’d manage to work this out?

I’m somewhat disappointed that the Unity docs team decided to actually write up documentation on this hack, but not follow it through.

More information on this hack: AngryAnt - Downloading the hydra

At the bottom of the post you’ll find an example bit of command-line for building an assembly out of your scripts. Note that you can do this more easily with something like Visual Studio or MonoDevelop.

The simple example in the post shows how to load the raw assembly as-is from a URL. Not an approach I would recommend. Aside from you probably wanting to keep the assembly in an asset bundle, you should definitely use some simple checksums to guard against man in the middle attacks.

Anywho, for the asset bundle approach, the trick is to save this .dll as a .bytes file in your Assets folder, which then gets imported as a TextAsset for you to store in an asset bundle and load at runtime.

You can find some example code of doing all of this in an automated fashion in my previous “Unity Hacks” talk: UnityHacks/Assets/Logic/Examples/Bundles at master · AngryAnt/UnityHacks · GitHub

The video is available here: https://vimeopro.com/unity3djp/unite-japan-2013-english-sessions/video/64381935

If you want to go for the gold star and fully automate the process of building unique content, including logic, for loading into already distributed runtimes, I did a writeup on that here: AngryAnt - Construct - though fair warning this is likely overkill for most use cases and not for the faint of heart. I only undertook that expedition because it was required for a contract (they had approval over the post before I published it).

Even if my inputs on the topic are six (eep!), three, and two years old, it should all still work as-is. Though as the documentation page points out, the very nature of your goal means that it will never work on an AOT runtime and with the advance of IL2CPP, it is going to continue to lose relevance.

I hope that this is useful and helps you reach your goal.

I know this is scary, but could you do an Eval() ?