Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do you safely remove assembly definitions without breaking all the scripts?

Discussion in 'Scripting' started by Pixitales, Nov 23, 2020.

  1. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    226
    How to safely remove assembly definition files?
     
    Last edited: Nov 23, 2020
  2. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    If removing an assembly causes your scripts to break then the script relies on that assembly, and you can't remove it.

    Unless you mean something different from "break" than what I expect it to mean (i.e. compiler errors). It might also be helpful to know what assembly you're trying to remove and why you want to remove it.
     
  3. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    226
    Its a big project and i want to remove all of them because they kinda slow. If you remove them one by one, it breaks your references/dependency. I probably need to start a brand new project.
     
  4. AylanJ123

    AylanJ123

    Joined:
    Oct 27, 2019
    Posts:
    4
    For anyone that stumbles here: This may happen because one doesn't know how to set up assembly definitions. It is supposed to make compilation faster because it isolates certain folders and only recompiles those files when a change occurs.
     
  5. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    They are supposed to make compilation faster, but they increase reload script assembly time, so this may compensate it.

    I am currently trying to remove some assemblies to make experiments to test this trade-of but when I remove the assemblies this causes a lot of compiler errors. It seems as if Unity is still trying to compile using the deleted assemblies (it doesn't find the definition of classes from different assemblies).

    So it seems just deleting the assemblies is not the proper way to tell Unity "I don't want to use these assemblies anymore, just use the default one". So, how can I do this?
     
  6. CodeRonnie

    CodeRonnie

    Joined:
    Oct 2, 2015
    Posts:
    284
    If you delete them one by one it will be confused halfway through because it's only halfway configured in one direction or the other.

    If one assembly that still exists halfway through removing them depend on code from one of the assembly definitions that was removed, then you will get compiler errors part of the way through because your defined assemblies not only are not referencing the default CSharp-Assembly.dll that scripts go into by default once removed from asmdefs, but they cannot reference that default assembly. You have to finish removing all of the asmdefs so the dependent scripts are all in the same assembly and can all see each other.

    Also, I know how difficult it can be to determine exactly which things depend on which other things. It took me some time, but I created over 20 interdependent dlls after taking the time to fully map out visually exactly which assemblies depend on which others with a visual graph. They live as asmdefs in one project, csproj projects in the solution where they are compiled to dlls, and compiled dlls in a different Unity project. This process also revealed a few things that I never would have found if I hadn't taken the time to explicitly comb through it. Having mapped it all out, I could delete my assemblies one by one without errors because I know exactly which ones I would have to delete, and in which order. However, I understand your pain and there being a lot of complexity in determing where all of your module dependencies lie.
     
    Last edited: Aug 23, 2023
  7. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    If I delete all of them but in the "wrong" order, does it work at the end?
     
  8. CodeRonnie

    CodeRonnie

    Joined:
    Oct 2, 2015
    Posts:
    284
    All of your code should just be in the default assembly at that point and all of the dependencies should be able to resolve, yes.
     
  9. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    I deleted all asmdefs from a package and there is still a lot of compiler errors.
     
  10. CodeRonnie

    CodeRonnie

    Joined:
    Oct 2, 2015
    Posts:
    284
    If you are willing, you can delete all of the old csproj files from your Unity directory (optional), and when you regenerate C# project files or recompile, check your solution in Visual Studio. What assemblies are listed there? If it only has the standard predefined Unity assemblies, then all of the former inter-assembly dependencies should be able to resolve. At that point I would be interested to know what the error messages say.
     
  11. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    I solved by (1) hovering the error in Visual Studio and choosing an option (NOT Add using directive, but something like this, it was the last option) and (2) moving the problematic files (which were using Nuint (or something like)) to a Editor folder.
     
    CodeRonnie likes this.