C
C#ā€¢5mo 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
CountingCardsā€¢5mo 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
CountingCardsā€¢5mo ago
mb wait was this ur answer to my question or were you fixing the link i sent
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
I think this may be out of my league šŸ˜…
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
lets start here, what asset and into the in-Editor assets folder? oh thats an actual object
CountingCards
CountingCardsā€¢5mo ago
No description
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo 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ā€¢5mo ago
donā€™t touch asmref (Assembly Definition Reference asset) files until later.
CountingCards
CountingCardsā€¢5mo ago
Oh I donā€™t know what that is
Loup&Snoop
Loup&Snoopā€¢5mo ago
yes, because now your code is in an assembly that depends on UnityEngine.InputSystem
CountingCards
CountingCardsā€¢5mo ago
Do I just add them based on the errors I encounter? That seems kinda janky
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
Iā€™ve never been more confused in my whole entire life šŸ˜¦
Loup&Snoop
Loup&Snoopā€¢5mo ago
you know how you have using UnityEngine etc in your code?
CountingCards
CountingCardsā€¢5mo ago
yeah arent those libraries
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo 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ā€¢5mo ago
almost if InputSystem changes, and your codeā€™s assembly depends on InputSystem, then the compiler needs to compile BOTH fresh
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
ok i understand that part
Loup&Snoop
Loup&Snoopā€¢5mo ago
the way I described, yes. It throws errors because the default unity assembly automatically depended on all your packages
CountingCards
CountingCardsā€¢5mo ago
oh ok
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
i understand
Loup&Snoop
Loup&Snoopā€¢5mo ago
thatā€™s why they need to be added now
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo ago
idfk it would be too simple
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo ago
no. but the errors it throws will let you know you actually missed a dependency
CountingCards
CountingCardsā€¢5mo ago
ok so i am expected to manually add every one i use ever
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
how do i know which to add? or is it simply just the .cinemachine one
No description
No description
Loup&Snoop
Loup&Snoopā€¢5mo ago
so, youā€™ll see a lot of asmdefs with editor in them
CountingCards
CountingCardsā€¢5mo ago
but can they all be in the same assembly if they dont use each other
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
you lost me
Loup&Snoop
Loup&Snoopā€¢5mo ago
they can. but then changing one makes you recompile everything
CountingCards
CountingCardsā€¢5mo ago
oh
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
yeah that makes sense i dont know what an asmdef is, is that the editor?
Loup&Snoop
Loup&Snoopā€¢5mo ago
so usually all your editor scripts go into one big separate assembly
CountingCards
CountingCardsā€¢5mo ago
and i just dont touch that ever
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
what about the current ones? do i want to add those? to the non-game new assembly
Loup&Snoop
Loup&Snoopā€¢5mo ago
i add only as needed
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
you lost me again xP
Loup&Snoop
Loup&Snoopā€¢5mo ago
i edited last sentencep your gameā€™s main assembly does NOT depend on ANY editor scripts
CountingCards
CountingCardsā€¢5mo ago
yes
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
and how do i identify an asmdef it just says .Editor?
Loup&Snoop
Loup&Snoopā€¢5mo ago
this dropdown shows all your asmdefs
CountingCards
CountingCardsā€¢5mo ago
so everything i see is an asmdef
Loup&Snoop
Loup&Snoopā€¢5mo ago
yeah, that little puzzle icon is an asmdef
CountingCards
CountingCardsā€¢5mo ago
ohh ok i understand what you mean now for which not to add
Loup&Snoop
Loup&Snoopā€¢5mo ago
yeah, editor asmdef should depend on package editor asmdefs. Ingame asmdef should not
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
whats the main assembly? i thought that already knew about everything
Loup&Snoop
Loup&Snoopā€¢5mo ago
yes the asmdef i told you to put in the root of Assets we will not be using the default assembly anymore
CountingCards
CountingCardsā€¢5mo ago
im confused
Loup&Snoop
Loup&Snoopā€¢5mo ago
so that will be our equivalent of it
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
but its not because it throws errors when i add the blank assembly object
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
oh ok u were talking about before i added anything yeah i get that much
Loup&Snoop
Loup&Snoopā€¢5mo ago
yes. this is the timeline ok, so now everything works.
CountingCards
CountingCardsā€¢5mo ago
i dont understand this part
Loup&Snoop
Loup&Snoopā€¢5mo ago
hold up.
CountingCards
CountingCardsā€¢5mo ago
or when to add asmdefs to already existing assemblys or to create new ones
Loup&Snoop
Loup&Snoopā€¢5mo ago
this asmdef that you just made in the root of Assets, it contains NO dependencies to editor code
CountingCards
CountingCardsā€¢5mo ago
No description
CountingCards
CountingCardsā€¢5mo ago
i just added the stuff that threw errors
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
there are no more errors
Loup&Snoop
Loup&Snoopā€¢5mo ago
there you go
CountingCards
CountingCardsā€¢5mo ago
why do i have to make a new folder?
Loup&Snoop
Loup&Snoopā€¢5mo ago
2 asmdefs cannot exist in the same folder
CountingCards
CountingCardsā€¢5mo ago
oh
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
yep you lost me again lmao
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
is that something i want
Loup&Snoop
Loup&Snoopā€¢5mo ago
sometimes, but not right now
CountingCards
CountingCardsā€¢5mo ago
alright
Loup&Snoop
Loup&Snoopā€¢5mo ago
the naming is very confusingp
CountingCards
CountingCardsā€¢5mo ago
how do i know what to add to the editor assembly? when it doesnt throw errors
Loup&Snoop
Loup&Snoopā€¢5mo ago
editor assembly will probably depend on your main assembly and any .Editor asmdefs if the packages folder
CountingCards
CountingCardsā€¢5mo ago
does that mean i put the editor assembly in the main assembly or vice versa
Loup&Snoop
Loup&Snoopā€¢5mo ago
but you only really need to manually write dependencies for the shit that YOU actually use in your code
CountingCards
CountingCardsā€¢5mo ago
just all of them? whether i know im using them or not even for the editor?
Loup&Snoop
Loup&Snoopā€¢5mo ago
you only need the ones you actually use for everything
CountingCards
CountingCardsā€¢5mo ago
idk which im using or are there no default
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
so input systems go inside editor assembly?
Loup&Snoop
Loup&Snoopā€¢5mo ago
only if the scripts that you have in the editor assembly use it which is currently none
CountingCards
CountingCardsā€¢5mo ago
doesnt the editor use it? outside of the game
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
ok and so the default setup doesnt count for the editor assembly? only extra scripts that i add?
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
oh ok so i dont care about the default unity stuff only scripts i add to modify it
Loup&Snoop
Loup&Snoopā€¢5mo ago
that just exists there
CountingCards
CountingCardsā€¢5mo ago
yeah now it makes sense
Loup&Snoop
Loup&Snoopā€¢5mo ago
UnityEngine has its own assembly.
CountingCards
CountingCardsā€¢5mo ago
do i add main assembly to editor assembly? or the other way around
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
so within main assembly, alongside the input system and cinemachine asmdefs, i add EditorAssembly?
Loup&Snoop
Loup&Snoopā€¢5mo 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
CountingCardsā€¢5mo ago
i mean the assembly i created the EditorAssembly i add that to main?
Loup&Snoop
Loup&Snoopā€¢5mo ago
Editor asmdef does reference the main assembly
CountingCards
CountingCardsā€¢5mo ago
im confused again
CountingCards
CountingCardsā€¢5mo ago
No description
No description
CountingCards
CountingCardsā€¢5mo ago
do i do this
Loup&Snoop
Loup&Snoopā€¢5mo ago
NO
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo ago
editor assembly into a folder in Assets because it cannot be in the same folder
CountingCards
CountingCardsā€¢5mo ago
thats what i did, first image
Loup&Snoop
Loup&Snoopā€¢5mo ago
this is wrong
CountingCards
CountingCardsā€¢5mo ago
No description
CountingCards
CountingCardsā€¢5mo ago
in this list do i put Editor Assembly in this list
Loup&Snoop
Loup&Snoopā€¢5mo ago
no i keep saying no
CountingCards
CountingCardsā€¢5mo ago
so i go to editor assembly and add main assembly?
Loup&Snoop
Loup&Snoopā€¢5mo ago
yes
CountingCards
CountingCardsā€¢5mo ago
ah ok that was the first question i asked but u said other way around xd
CountingCards
CountingCardsā€¢5mo ago
No description
CountingCards
CountingCardsā€¢5mo ago
just to double check, i can apply this?
Loup&Snoop
Loup&Snoopā€¢5mo ago
there you go. done
CountingCards
CountingCardsā€¢5mo ago
alright cool
Loup&Snoop
Loup&Snoopā€¢5mo ago
gg
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo ago
yes
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo ago
but i dont care about that right?
Loup&Snoop
Loup&Snoopā€¢5mo ago
thatā€™s like the whole point of using assembly definitions. So your code wonā€™t have to recompile everything all at once
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo 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
CountingCardsā€¢5mo 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ā€¢5mo ago
this is way beyond the scope of this thread, brother. this is just more generic assembly stuff
CountingCards
CountingCardsā€¢5mo 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ā€¢5mo ago
you got the basics. good luck
CountingCards
CountingCardsā€¢5mo ago
thanks for the help. ill reference your previous messages for when i need Assemble Definition References
Loup&Snoop
Loup&Snoopā€¢5mo 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
More Posts
Exam Prep OOP(Constructors , Inheritance , interface , polymorphism , Exception Handlingtopics i will be covering inheritance constructors static sealed for both methods and classes poHow to check options for null?I have this: ```cs var options = Configuration.GetSection(nameof(Patterns)); services.Configure<PattType Inference strategies?I'm generating Class Definition from XML. And currently I just save the Value strings. But I want stGenerating input fields for each element in an array in Blazor WASMI'm trying to generate an input field for each element in an array, and have the input field bind thBinarySerialization - need some design helpHi, this is my first foray into lower level programming and I could use some help. I am writing a Dāœ… why ArgumentException.ThrowIfNullOrEmpty(); is only for string?I have following: ```cs public class A { A(AnotherClass AC) { // how to cheAspNet.Core OpenTelemetry AzureMonitorLogExporter doesn't include ILogger name in AppInsight traces.ILogger log messages get written to app insights but there is some info missing compared to writing āœ… Best practices for WPF context aware documentationAll projects in the company I work at are made in WinForms .NET 4.8 and provide CHM help file documeDoes CultureInfo ever matter here?I have some code that is generating some warnings: ``` CA1305: The behavior of 'long.ToString()' coRun Query in asp.net mvcIn ASP.net mvc I have a order by descending query in a controller how would i excute the the query