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

Failed to build player after using assembly definition files

Discussion in 'Experimental Scripting Previews' started by optimise, Jan 17, 2018.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    After I add Cinemachine as assembly definition file, Unity 2017.3.0f3 will complain with a lot of errors when building the player.

     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    You have to set up a separate asmdef for the Editor folder, and mark it as editor-only.
     
    Phenotype likes this.
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    I think it needs to have something that can auto scan & resolve for the Editor folder. It's really troublesome that needs to add asmdef file one by one to every Editor folder and resolve all the dependencies.
     
    t-matsunaga-gu3 likes this.
  4. steffen-itterheim

    steffen-itterheim

    Joined:
    Nov 10, 2015
    Posts:
    24
    Hence why I chose to go with one Scripts and one Editor folder, of course each with subfolders but it enables you ti have one "fallback" asmdef for those folders you don't have or need separate asmdefs.
     
  5. Birkeman

    Birkeman

    Joined:
    Apr 22, 2013
    Posts:
    21
    It's quite annoying having to add boilerplate definition files to Editor folders to solve this issue. When this feature gets out of beta will that still be a thing we will have to do or will the build system exclude scripts in Editor folders like it does when there's no assembly definition files? It's a quite big issue with an otherwise great feature
     
    Alverik likes this.
  6. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    @superpig Do you know how many editor folders do I have in the project? Many. I don`t even know where they are and some of them are scripts managed by external code which I cannot change. How to use Unity Testing when this is the case?
     
    Michael_Berna likes this.
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    As long as there's no asmdef in any parent of an Editor folder then it will behave like it always has done.

    If you're trying to write tests, you will need to have the code that you are testing inside its own folder so that you can add an asmdef. Do not add an asmdef in the root of your project, or you'll turn off all the 'magic' folder name behaviour for your whole project.
     
  8. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    So basiscally I have 2 choices, either I spread my tests all over my project, or I spread asmdefs all over my project (including within code I don't manage)?

    For now I'll be using my own testing framework, but thanks for the quick response.
     
  9. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Yes, you are supposed to do the latter. The intended design here is that you organise the code in your project into systems, e.g.

    Assets/EnemyAI - contains all your enemy AI code
    Assets/EnemyAI/Editor - contains Editor scripts that go with your enemy AI code (e.g. custom inspectors for your enemy AI components)
    Assets/EnemyAI/Tests - contains unit tests for your enemy AI code

    You'd have an asmdef file in each folder, with references set up between them. This would not just allow your tests to work; it should also reduce your compile times, and allow you to use keywords like
    internal
    to strengthen the architecture in your codebase.
     
  10. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    I don't manage most of the code in my project. I cannot force the developers of the assets I use to create asmdefs. I cannot create pull requests for every open source library I am using. I cannot wire up correctly all dependencies between the definitions (most of the time these are hidden and hard to spot). The inspector for the asmdef is really hacky and weird to use.

    Even if I put asmdefs all over, every single asset I update will break the changes I have made and undo the dependency wiring. Why there is no "migration" solution? Why working with unity can be so rough some times? This kind of experience really degrades the general quality of the software.

    At least there should be a tool for this system, so we can identify where editor files are, which are native, and automatically try to setup this. There are a few community tools that try to do this, but none work correctly in my project (large code base, a huge amount of external libraries + assets).

    Anyway, thanks for the support! At least now I know exactly what is going on. For those facing the same problem, I'm about to release a testing tool that doesn't require assemblies.
     
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    We have been working on a tool to automatically upgrade projects with asmdefs. In 2019.2 we added the assembly definition reference (asmref) which will be used as part of this process, it allows for adding multiple directories to an asmdef even when they are not part of the hierarchy. So all the editor folders can now be added to a single asmdef instead of having one per directory. We should have something later on the year.
     
    IsDon, lucasmontec and dri_richard like this.
  12. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    This is exatcly what we wanted to hear. A solution that fits most of our projects, is easier to implement and still is somewhat backwards compatible with unity's own previous solution. Thanks for this.

    For everyone else, I still have created my own testing framework. It is available here: https://gitlab.com/lucasmontec/zunit

    It is not the most robust solution but it works and it offers quite a few ways to test your code. It is compatible with asmdefs but doesn't require them.