Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feedback Warn when you're using asmdefs but a cs file is not under an asmdef

Discussion in 'Editor & General Support' started by AcademyOfFetishes, May 24, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    I have a feature request: When your project uses some asmdefs but there are some CS files outside of an asmdef, unity should give a warning and it should mention the file that's outside of an asmdef.

    e.g.,
    Warning: Assets/Scripts/Foo.cs is not in an asmdef.  Your whole project will compile on every change which will increase compile times.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,404
    Having this warning would imply that the user is doing something wrong when in fact it's absolutely fine to work this way, there is no guarantee it will be slower and the difference could be negligible once you factor in the assembly reload time.
    If the user is anything like me they will just ignore the warnings, thats what they're for, right ;)

    If you want to do this in your own project you could write an editor script to check. Iterate through the scripts in the project(use AssetDatabase) and check them with CompilationPipeline.
    e.g https://docs.unity3d.com/ScriptRefe...onPipeline.GetAssemblyNameFromScriptPath.html
     
    AcademyOfFetishes likes this.
  3. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    You could do this, but I can't imagine a scenario where I'd want to use asmdefs for half my code.

    That sounds like a great compromise. I'd just warn if GetAssemblyNameFromScriptPath returned null, right?
     
    karl_jones likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,404
    Yes, that should work.

    Most projects are like this now since all our packages use asmdefs.
     
  5. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    Sorry, but don't the docs imply the opposite? In fact they say:

    Note: Although not strictly required, Unity recommends that whenever you use Assembly Definitions in a project, you do so for all of the code in your project. Otherwise, when you change scripts in one of the predefined assemblies, Unity must still recompile all the code in your project, since the predefined assemblies automatically depend upon any assemblies you create using an Assembly Definition.
    At what point will "asmdefs everywhere" benefit me? I know the answer is going to be, "it depends," but there must be some heuristic out there I can use to consider "asmdefs everywhere." e.g., When there were 500 .cs files in a project, asmdefs helped. When there were 250, it didn't make a difference.

    Every time I import a new library, I spend 30-60 minutes figuring how to create asmdefs for it. Is this usually a waste of time or usually a good idea?
     
    Last edited: May 26, 2019
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,404
    It really depends on the project. It's true that changing files not in an asmdef will trigger compilation for all however In a simple project this time is normally very small and it's the assembly reload that takes the longest part of the process. Assembly reload can actually get longer with more asmdefs so there's a sweet spot where that time is negated by the reduced compilation time. If you are putting every library you have into its own asmdef then that may make things slower (if there's a lot), it's usually better to put all the library code into a single asmdef, this is one of the reasons we added asmrefs in 2019.2.

    As a project gets bigger then it can make a difference so big projects should certainly use it. We are working on some better profiling tools to help setup asmdefs which should make this easier to see in the future.
     
    Last edited: May 26, 2019
    AcademyOfFetishes likes this.
  7. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    Thanks for the information! I'm glad to hear the tools are coming, but is there anything I can do to check performance today? I've literally been using my cell phone's stopwatch to check for compile times. I think the editor log provides some useful information, but I'm not sure if it breaks it down enough to know if asmdefs are helping or hurting.
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,404
    You can do something like this https://gist.github.com/karljj1/9c6cce803096b5cd4511cf0819ff517b
     
    AcademyOfFetishes likes this.