Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom assembly build location

Discussion in 'Experimental Scripting Previews' started by Ramobo, Nov 24, 2019.

  1. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    (I'm getting tired of this...)

    Bottom line: I need to be able to tell Unity where to build an assembly to (StreamingAssets), forget about it: let me manage the loading, and probably resolve scripts by full qualification and assembly signature, or something. From a user perspective, a "build destination" field and a "loaded automatically" checkbox on assembly definitions should work.

    Reasoning: I'm making a modding system and want to dogfeed on it as much as possible, meaning building my game as mods that go in StreamingAssets instead of {persistentDataPath}. I can fight the editor and engine (not that it's uncommon) and just move those assemblies from Managed into StreamingAssets using build post processing, but then any attached scripts won't resolve (the scenes are in addressables bundles that I also want to move to proper folders). I suppose changing the way scripts are resolved could work. This begs the question: How does Unity resolve attached scripts at runtime?
    In fact, I get the following error in Player.log for each of those assemblies that I move out of Managed:
    Code (CSharp):
    1. Fallback handler could not load library {BuildPath}/{ProductName}_Data/Mono/data-{X}.dll
    It works fine in the editor. As I said, the scripts don't resolve. I load the assemblies before scenes that contain references to those scripts get loaded. I tried Assembly.Load() and AppDomain.CurrentDomain.Load().
     
    Last edited: Dec 6, 2019
  2. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    I'd really like to know about this.
     
  3. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
  4. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
  5. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    136
    Hi @Ramobo sorry that you have not gotten any feedback for such a long time.

    You can use precompiled assemblies, but Unity needs to handle the loading.
    When we load the Assemblies we do alot of things, like building up caches and scanning for Monobehaviors that produce assets so you can add them on GameObjects.
     
  6. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    136
    So that assembly need to be either in the Assets folder, or a Package
     
  7. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    I think you misunderstood something. What I ask for is:
    • A string on assembly definitions to change their build location. I'd need that to be in a folder of my choice in StreamingAssets.
    • A checkbox on assembly definitions to disable Unity loading them automatically.
    • From what you described about Unity's special loading process, we'd also need something like `UnityEngine.Application.LoadAssembly(string path)`, which loads the assembly at `path` and does that extra stuff. If there's an internal method for this, I can't think why it could be hard to wrap like Unity already does for much of everything.

    For reference, here's what I envision:
    • The application starts on ModLoaderScene, whose only script is `ModLoader`.
    • `ModLoader` loads addressables content then assemblies. Addressables need loading first because the mods might want to get something from there in their `OnLoaded` method.
    • The next scene, which is addressable, is loaded. From here on it's no longer the mod loader's problem. Right now, scripts don't resolve because that extra stuff in the loading process didn't happen.
     
  8. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    136
    I think that, if you need to place your dll another place or have more control of output dir / how you compile, you should compile the DLL your self. But... Rereading your initial post, it sounds like this is only a problem in the Player? There it should just be up to how we load the assembly, and yes when moving it to another folder it will not load that assembly. We have on our to-do, to get Assembly.Load to work with our systems. Can you make a feature request about it so we can prioritise accordingly?
     
  9. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    I really think that the Editor should be as convenient as possible instead of having to work around it at every turn. Besides, if I compile myself to somewhere in the project, they'll get thrown in Managed anyway. If I compile myself and add them in the build, they won't be available in the Editor. In any case, my only motivation for compiling myself would be moving the assemblies on build, and that prevents them from being loaded.

    Correct. Since the Editor compiles to ScriptAssemblies and I copy instead of moving my mod stuff to StreamingAssets in play mode, they get loaded.

    Is this like the `Application.LoadAssembly` I described? And what do you mean "our systems"? The platforms that Unity supports?

    Where? Feedback is gone, I don't see a section for it in the forum and bugs doesn't seem appropriate for this.
     
  10. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    136
    I mean that when you use the .Net Assembly Load, we do all the things we do as we normally do when loading the domain, so all monobehaviors ect will work as expected, then you could just load the assembly from where its moved to by your post processor.

    Oh you are right it is :(. I will write this request to our producer
     
    LeonhardP likes this.
  11. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    Ok. So, what do you refer to by "your systems"? And what about it isn't working in "your systems"?