C
C#ā€¢11mo ago
CountingCards

Assembly Definitions

Can someone dumb this down for me? I'm trying to decrease compile times for unity and came across this(image + link) but this seems really complicated šŸ˜… https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html#:~:text=An%20assembly%20is%20a%20C%23,define%20references%20to%20other%20assemblies.&text=Every%20time%20you%20change%20one,time%20for%20iterative%20code%20changes.
No description
154 Replies
CountingCards
CountingCardsOPā€¢11mo ago
if this is something i shouldnt bother with or touch, let me know. i just dont like having to wait 20+ seconds every time i save a script šŸ˜¦
CountingCards
CountingCardsOPā€¢11mo ago
mb wait was this ur answer to my question or were you fixing the link i sent
Loup&Snoop
Loup&Snoopā€¢11mo ago
i went through this recently Unity by default puts ALL of your scripts into a default assembly called AssemblyC#-default or something like that This default assembly depends on all your packages in order to add an assembly definition, in unity, your two options are: 1) Define your own dll which explicitly calls out every package dll etc that it depends on 2) hook up Unity Assembly Definition assets a Unity Assembly Definition makes an assembly, and automatically adds ALL code in that folder or a sub folder to that assembly UNLESS it is covered by either 1) its own .dll or 2) One of the subfolders has an assembly definition (asmdef). In which case it does not include that folder or any subfolders to make an Assembly definition that is equivalent, start by making an asmdef in your root folder, and make it depend on all the .asmdef that you use in your Packages folder. that is what tripped me up for the longest time.
CountingCards
CountingCardsOPā€¢11mo ago
I think this may be out of my league šŸ˜…
Loup&Snoop
Loup&Snoopā€¢11mo ago
itā€™s not hard, but it will only benefit you if you can actually totally separate a large chunk of your code intona separate assembly right now, you can just put an Assembly Definition asset directly into your Assets folder. and then on the little list of dependencies in the inspector, you add all the asmdefs for packages you use. Like NaughtyAttributes.core Like typical unity inspector, it will show you only the asmdefs in your project. And since you havenā€™t made any, it will only show you package asmdefs If you do this, then all of your code should still work the same as before (except maybe anything that depends on assembly qualified names of types, which you probably have none of) ā€”ā€” Later, you can add assembly definitions to different folders, if everything in that folder is kind of separate from the rest of your project. Then make the root asmdef depend on that new subfolderā€™s asmdef. Now Unity wonā€™t recompile anything in that subfolder unless you modify it. Understand?
CountingCards
CountingCardsOPā€¢11mo ago
lets start here, what asset and into the in-Editor assets folder? oh thats an actual object
CountingCards
CountingCardsOPā€¢11mo ago
No description
CountingCards
CountingCardsOPā€¢11mo ago
is this where i list all of the "asmdefs" for packages i use? and i dont know where to find/reference those
Loup&Snoop
Loup&Snoopā€¢11mo ago
I assume all of your own scripts are in subfolders of subfolders of subfoldersā€¦ of the Assets folder Keep in mind there is Assembly Definition (what I was talking about), and Assembly Definition Reference. Assembly Definition Reference is an asset that targets an Assembly Definition to add the folder that the assembly definition reference is in, to the set of folders that the Assembly Definition will try to consolidate into one assembly. In the inspector, Assembly Definition has a field for Assembly Definition References, which is actually a list of asmdefs that this assetā€™s assembly depends on. And is not an Assembly Definition Reference asset. Yes it is confusing add one entry to the list, then click on the empty entry, and unity will show you any asmdefs in the project (packages included) they should have obvious names that reflect the relevant namespace like if you use Unity Tilemaps, you would select UnityEngine.Tilemaps, which is the namespace that Tilemaps is in
CountingCards
CountingCardsOPā€¢11mo ago
I see, but I donā€™t know which I use Oh I see, I added input system and a lot of errors disappeared
Loup&Snoop
Loup&Snoopā€¢11mo ago
donā€™t touch asmref (Assembly Definition Reference asset) files until later.
CountingCards
CountingCardsOPā€¢11mo ago
Oh I donā€™t know what that is
Loup&Snoop
Loup&Snoopā€¢11mo ago
yes, because now your code is in an assembly that depends on UnityEngine.InputSystem
CountingCards
CountingCardsOPā€¢11mo ago
Do I just add them based on the errors I encounter? That seems kinda janky
Loup&Snoop
Loup&Snoopā€¢11mo ago
you canā€™t use code from outside an assembly unless the assembly of your corde depends on the assembly of the code you are trying to work with if you are using InputSystem, your assembly needs to depend on it
CountingCards
CountingCardsOPā€¢11mo ago
Iā€™ve never been more confused in my whole entire life šŸ˜¦
Loup&Snoop
Loup&Snoopā€¢11mo ago
you know how you have using UnityEngine etc in your code?
CountingCards
CountingCardsOPā€¢11mo ago
yeah arent those libraries
Loup&Snoop
Loup&Snoopā€¢11mo ago
you are bringing in code from a different namespace when you download a package, that package is normally in its own assembly and usually also with its own namespace assemblies change what code is compiled when if your code is using InputSystem, and InputSystem is a different assembly, then your codeā€™s assembly needs to depend on whatever assemnly has InputSystem because the whole InputSystem namespace doesnā€™t exist outside of that assembly
CountingCards
CountingCardsOPā€¢11mo ago
ok so by adding this assembly and telling it to reference Input System, it will only compile Input System scripts?
Loup&Snoop
Loup&Snoopā€¢11mo ago
almost if InputSystem changes, and your codeā€™s assembly depends on InputSystem, then the compiler needs to compile BOTH fresh
CountingCards
CountingCardsOPā€¢11mo ago
does this new assembly become the only assembly? why does it throw errors if i have nothing in its references
Loup&Snoop
Loup&Snoopā€¢11mo ago
if your code changes, and Inputsystem does not change, but your codeā€™s assembly depends on InputSystem, then compiler will recompile your code, but NOT InputSystem
CountingCards
CountingCardsOPā€¢11mo ago
ok i understand that part
Loup&Snoop
Loup&Snoopā€¢11mo ago
the way I described, yes. It throws errors because the default unity assembly automatically depended on all your packages
CountingCards
CountingCardsOPā€¢11mo ago
oh ok
Loup&Snoop
Loup&Snoopā€¢11mo ago
weā€™re first making one root assembly to replace the default assembly the root assembly I told you to make does NOT automatically depend on all your packages
CountingCards
CountingCardsOPā€¢11mo ago
i understand
Loup&Snoop
Loup&Snoopā€¢11mo ago
thatā€™s why they need to be added now
CountingCards
CountingCardsOPā€¢11mo ago
why cant i just tell it to depend on all my packages? and if i dont use them, it wont compile them every time
Loup&Snoop
Loup&Snoopā€¢11mo ago
idfk it would be too simple
CountingCards
CountingCardsOPā€¢11mo ago
fair enough so am i supposed to add the packages based on the errors it throws? granted i can go off of just.. the ones i know im using but i dont think ill remember to add every single time
Loup&Snoop
Loup&Snoopā€¢11mo ago
no. but the errors it throws will let you know you actually missed a dependency
CountingCards
CountingCardsOPā€¢11mo ago
ok so i am expected to manually add every one i use ever
Loup&Snoop
Loup&Snoopā€¢11mo ago
like if you use InputSystem functions and classes, but never write using InputSystem, compiler throws error because it has no idea wtf youā€™re talking about same thing with assembly but you donā€™t want to micromanage a lot of tiny assemblies remember assembly dependencies cannot be cyclic. So if classA uses class B, and class B uses class A, then both have to be in the same assembly but if you have A B C all use each other, and nothing else, then A B C can all be one separate assembly
CountingCards
CountingCardsOPā€¢11mo ago
how do i know which to add? or is it simply just the .cinemachine one
No description
No description
Loup&Snoop
Loup&Snoopā€¢11mo ago
so, youā€™ll see a lot of asmdefs with editor in them
CountingCards
CountingCardsOPā€¢11mo ago
but can they all be in the same assembly if they dont use each other
Loup&Snoop
Loup&Snoopā€¢11mo ago
editor basically always means UnityEditor, like inspector. Almost always, editor scripts are in an editor assembly definition, and this editor asmdef depends on the core stuff of your project
CountingCards
CountingCardsOPā€¢11mo ago
you lost me
Loup&Snoop
Loup&Snoopā€¢11mo ago
they can. but then changing one makes you recompile everything
CountingCards
CountingCardsOPā€¢11mo ago
oh
Loup&Snoop
Loup&Snoopā€¢11mo ago
your unity code for your actual game should never depend on the code for your custom unity editor. Like the scripts that change the inspector because your game isnā€™t run in unity editor
CountingCards
CountingCardsOPā€¢11mo ago
yeah that makes sense i dont know what an asmdef is, is that the editor?
Loup&Snoop
Loup&Snoopā€¢11mo ago
so usually all your editor scripts go into one big separate assembly
CountingCards
CountingCardsOPā€¢11mo ago
and i just dont touch that ever
Loup&Snoop
Loup&Snoopā€¢11mo ago
asmdef is the file extension for assembly definition asset that is fine, but you will download many packages with .Editor asmdefs we do not want any of that shit in the actual game
CountingCards
CountingCardsOPā€¢11mo ago
what about the current ones? do i want to add those? to the non-game new assembly
Loup&Snoop
Loup&Snoopā€¢11mo ago
i add only as needed
CountingCards
CountingCardsOPā€¢11mo ago
ok.. going back to whether or not i need a new assembly for in-game packages, i need help understanding that
Loup&Snoop
Loup&Snoopā€¢11mo ago
i have my editor asmdef, and it depends on my main assembly, and all my package editor asmdefs. My main assembly does NOT depend on any packageā€™s .Editor asmdefs, or else you fucked up
CountingCards
CountingCardsOPā€¢11mo ago
you lost me again xP
Loup&Snoop
Loup&Snoopā€¢11mo ago
i edited last sentencep your gameā€™s main assembly does NOT depend on ANY editor scripts
CountingCards
CountingCardsOPā€¢11mo ago
yes
Loup&Snoop
Loup&Snoopā€¢11mo ago
therefore, your main ingame assembly does NOT depend on any of the .editor asmdefs from your packages because those asmdefs correspond to editor code which we donā€™t want
CountingCards
CountingCardsOPā€¢11mo ago
and how do i identify an asmdef it just says .Editor?
Loup&Snoop
Loup&Snoopā€¢11mo ago
this dropdown shows all your asmdefs
CountingCards
CountingCardsOPā€¢11mo ago
so everything i see is an asmdef
Loup&Snoop
Loup&Snoopā€¢11mo ago
yeah, that little puzzle icon is an asmdef
CountingCards
CountingCardsOPā€¢11mo ago
ohh ok i understand what you mean now for which not to add
Loup&Snoop
Loup&Snoopā€¢11mo ago
yeah, editor asmdef should depend on package editor asmdefs. Ingame asmdef should not
CountingCards
CountingCardsOPā€¢11mo ago
rn i need to understand when to make a new assembly for in-game packages or to add them to an already existing assembly for in-game packages and should i make a new assembly only for .editor asmdefs (and which to add there)
Loup&Snoop
Loup&Snoopā€¢11mo ago
if you donā€™t include an editor asmdef as a dependency of the main assembly, and your compiler is confused, you fucked up.
CountingCards
CountingCardsOPā€¢11mo ago
whats the main assembly? i thought that already knew about everything
Loup&Snoop
Loup&Snoopā€¢11mo ago
yes the asmdef i told you to put in the root of Assets we will not be using the default assembly anymore
CountingCards
CountingCardsOPā€¢11mo ago
im confused
Loup&Snoop
Loup&Snoopā€¢11mo ago
so that will be our equivalent of it
CountingCards
CountingCardsOPā€¢11mo ago
so i add in-game packages to the main assembly i dont add editor packages to the main assembly if i dont add editor packages to the main assembly and compiler = confused, i did something wrong
Loup&Snoop
Loup&Snoopā€¢11mo ago
the moment you put an asmdef, it collects everything (all .cs from folders and subfolders) into an assembly for it. right now, everything you have is in the default C# assembly because you have no asmdefs
CountingCards
CountingCardsOPā€¢11mo ago
but its not because it throws errors when i add the blank assembly object
Loup&Snoop
Loup&Snoopā€¢11mo ago
the moment you add an asmdef, compiler is confused because you reference code from an assembly you donā€™t depend on. so you add dependencies to that asmdef, so it knows to make the assembly depend on the assemblies containing the missing code
CountingCards
CountingCardsOPā€¢11mo ago
oh ok u were talking about before i added anything yeah i get that much
Loup&Snoop
Loup&Snoopā€¢11mo ago
yes. this is the timeline ok, so now everything works.
CountingCards
CountingCardsOPā€¢11mo ago
i dont understand this part
Loup&Snoop
Loup&Snoopā€¢11mo ago
hold up.
CountingCards
CountingCardsOPā€¢11mo ago
or when to add asmdefs to already existing assemblys or to create new ones
Loup&Snoop
Loup&Snoopā€¢11mo ago
this asmdef that you just made in the root of Assets, it contains NO dependencies to editor code
CountingCards
CountingCardsOPā€¢11mo ago
No description
CountingCards
CountingCardsOPā€¢11mo ago
i just added the stuff that threw errors
Loup&Snoop
Loup&Snoopā€¢11mo ago
then weā€™re going to a different folder, we add an asmdef for editor, we make it depend on any .Editor asmdefs we need, and depend on the main assembly we made before. and now that folder and everything in it is in a separate editor assembly read the errors
CountingCards
CountingCardsOPā€¢11mo ago
there are no more errors
Loup&Snoop
Loup&Snoopā€¢11mo ago
there you go
CountingCards
CountingCardsOPā€¢11mo ago
why do i have to make a new folder?
Loup&Snoop
Loup&Snoopā€¢11mo ago
2 asmdefs cannot exist in the same folder
CountingCards
CountingCardsOPā€¢11mo ago
oh
Loup&Snoop
Loup&Snoopā€¢11mo ago
that Editor folder is going to contain any editor scripts you ever make for your game which might be none, but now you have a separate place for them
CountingCards
CountingCardsOPā€¢11mo ago
when do i use an assembly definition reference? oh nvm thats just what u mean when u say asmdef and the option to create one is for if i wanted to make a package or whatever i assume
Loup&Snoop
Loup&Snoopā€¢11mo ago
lets say you have myClassA.cs in folder A, and myClassB.cs in folder B. You want them in one assembly, but they arenā€™t subfolders, they are in different folders, and you just want to tie them together. Give folder A an asmdef to define the assembly. Give folder B an asmref (REF) that targets the asmdef if folder A now A and B are part of one assembly
CountingCards
CountingCardsOPā€¢11mo ago
yep you lost me again lmao
Loup&Snoop
Loup&Snoopā€¢11mo ago
that is an Assembly Definition Reference Asset an asmref file just connects the contents of one folder to be counted for an asmdef asmrefs just change the part where asmdefs check all folders and subfolders
CountingCards
CountingCardsOPā€¢11mo ago
is that something i want
Loup&Snoop
Loup&Snoopā€¢11mo ago
sometimes, but not right now
CountingCards
CountingCardsOPā€¢11mo ago
alright
Loup&Snoop
Loup&Snoopā€¢11mo ago
the naming is very confusingp
CountingCards
CountingCardsOPā€¢11mo ago
how do i know what to add to the editor assembly? when it doesnt throw errors
Loup&Snoop
Loup&Snoopā€¢11mo ago
editor assembly will probably depend on your main assembly and any .Editor asmdefs if the packages folder
CountingCards
CountingCardsOPā€¢11mo ago
does that mean i put the editor assembly in the main assembly or vice versa
Loup&Snoop
Loup&Snoopā€¢11mo ago
but you only really need to manually write dependencies for the shit that YOU actually use in your code
CountingCards
CountingCardsOPā€¢11mo ago
just all of them? whether i know im using them or not even for the editor?
Loup&Snoop
Loup&Snoopā€¢11mo ago
you only need the ones you actually use for everything
CountingCards
CountingCardsOPā€¢11mo ago
idk which im using or are there no default
Loup&Snoop
Loup&Snoopā€¢11mo ago
compiler will imediately let you know when you fuck up because it will tell you that X file does not know about Y namespace
CountingCards
CountingCardsOPā€¢11mo ago
so input systems go inside editor assembly?
Loup&Snoop
Loup&Snoopā€¢11mo ago
only if the scripts that you have in the editor assembly use it which is currently none
CountingCards
CountingCardsOPā€¢11mo ago
doesnt the editor use it? outside of the game
Loup&Snoop
Loup&Snoopā€¢11mo ago
the asmdef only applies to code in that folder and subfolders if that folder and subfolders are empty, there is no actual code in the assembly
CountingCards
CountingCardsOPā€¢11mo ago
i dont understand what counts as a Editor asmdef here because i use input system in the unity editor to assign hotkeys for in game
Loup&Snoop
Loup&Snoopā€¢11mo ago
you see the asmdef Cinemachine.Editor that is an asmdef intended to ONLY be used for unity editor mode and never for the actual game so your game assembly does not depend on Cinemachine.Editor
CountingCards
CountingCardsOPā€¢11mo ago
ok and so the default setup doesnt count for the editor assembly? only extra scripts that i add?
Loup&Snoop
Loup&Snoopā€¢11mo ago
but maybe you write an editor script that uses stuff in Cinemachine.Editor. then you will want that in your special editor asmdef
CountingCards
CountingCardsOPā€¢11mo ago
oh ok so i dont care about the default unity stuff only scripts i add to modify it
Loup&Snoop
Loup&Snoopā€¢11mo ago
that just exists there
CountingCards
CountingCardsOPā€¢11mo ago
yeah now it makes sense
Loup&Snoop
Loup&Snoopā€¢11mo ago
UnityEngine has its own assembly.
CountingCards
CountingCardsOPā€¢11mo ago
do i add main assembly to editor assembly? or the other way around
Loup&Snoop
Loup&Snoopā€¢11mo ago
the autoreferenced checkbox automatically puts all that stuff in there other way around editor code depends on your code because it needs to know what classes it is an editor of
CountingCards
CountingCardsOPā€¢11mo ago
so within main assembly, alongside the input system and cinemachine asmdefs, i add EditorAssembly?
Loup&Snoop
Loup&Snoopā€¢11mo ago
the classes for your game do not need to know about the editor classes that edit them NO main assembly does not contain anything with the word ā€œEditorā€ in it
CountingCards
CountingCardsOPā€¢11mo ago
i mean the assembly i created the EditorAssembly i add that to main?
Loup&Snoop
Loup&Snoopā€¢11mo ago
Editor asmdef does reference the main assembly
CountingCards
CountingCardsOPā€¢11mo ago
im confused again
CountingCards
CountingCardsOPā€¢11mo ago
No description
No description
CountingCards
CountingCardsOPā€¢11mo ago
do i do this
Loup&Snoop
Loup&Snoopā€¢11mo ago
NO
CountingCards
CountingCardsOPā€¢11mo ago
isnt that what you said here? in what i sent, i put the Editor Assembly in the Main Assembly, is it supposed to be the other way around?
Loup&Snoop
Loup&Snoopā€¢11mo ago
editor assembly into a folder in Assets because it cannot be in the same folder
CountingCards
CountingCardsOPā€¢11mo ago
thats what i did, first image
Loup&Snoop
Loup&Snoopā€¢11mo ago
this is wrong
CountingCards
CountingCardsOPā€¢11mo ago
No description
CountingCards
CountingCardsOPā€¢11mo ago
in this list do i put Editor Assembly in this list
Loup&Snoop
Loup&Snoopā€¢11mo ago
no i keep saying no
CountingCards
CountingCardsOPā€¢11mo ago
so i go to editor assembly and add main assembly?
Loup&Snoop
Loup&Snoopā€¢11mo ago
yes
CountingCards
CountingCardsOPā€¢11mo ago
ah ok that was the first question i asked but u said other way around xd
CountingCards
CountingCardsOPā€¢11mo ago
No description
CountingCards
CountingCardsOPā€¢11mo ago
just to double check, i can apply this?
Loup&Snoop
Loup&Snoopā€¢11mo ago
there you go. done
CountingCards
CountingCardsOPā€¢11mo ago
alright cool
Loup&Snoop
Loup&Snoopā€¢11mo ago
gg
CountingCards
CountingCardsOPā€¢11mo ago
gg no rematch so now im good to put everything i use in the main assembly, except for anything i use to do with editor, which goes in editor assembly?
Loup&Snoop
Loup&Snoopā€¢11mo ago
yes
CountingCards
CountingCardsOPā€¢11mo ago
so what did it mean when u said earlier about different assemblies if x and y reference arent used with each other this part
Loup&Snoop
Loup&Snoopā€¢11mo ago
that is the basics of an assembly In this case, A B and C must all be in an assembly together in order to use each otherā€™s code. but because they donā€™t depend on anything else, they can be in their own assembly
CountingCards
CountingCardsOPā€¢11mo ago
but i dont care about that right?
Loup&Snoop
Loup&Snoopā€¢11mo ago
thatā€™s like the whole point of using assembly definitions. So your code wonā€™t have to recompile everything all at once
CountingCards
CountingCardsOPā€¢11mo ago
like what if one script uses A , B, C and D and another uses D and E would A B C and D be in its own assembly, then D and E in their own? or would E be included with ABCD because D is included in ABCD and AE
Loup&Snoop
Loup&Snoopā€¢11mo ago
not necessarily as long as ABC only use each other, they can be in a separate assembly (or added as one unit to any other assembly) if a script uses A, then its assembly needs to be OR contains the assembly with ABC
CountingCards
CountingCardsOPā€¢11mo ago
but can one be used in multiple? like A B in an assembly, and A C in a different assembly
Loup&Snoop
Loup&Snoopā€¢11mo ago
this is way beyond the scope of this thread, brother. this is just more generic assembly stuff
CountingCards
CountingCardsOPā€¢11mo ago
alright i wasnt sure because you mentioned it so i think everything is good compiling after a one-character change still took a good 5 seconds but i think its down from previously anything else you think i should know?
Loup&Snoop
Loup&Snoopā€¢11mo ago
you got the basics. good luck
CountingCards
CountingCardsOPā€¢11mo ago
thanks for the help. ill reference your previous messages for when i need Assemble Definition References
Loup&Snoop
Loup&Snoopā€¢11mo ago
oh and try to write code that fits into a separate assembly, by making things that donā€™t depend on your main code base so you can combine them into a separate assembly
Want results from more Discord servers?
Add your server