Assembly Definitions

Will this tutorial series also cover the use of Assembly definitions?

1 Like

No, it doesn’t

The course does not cover Assembly definitions, but they aren’t terribly difficult to implement.

Creating an Assembly Definition is as easy as creating an Assembly Definition within the directory. Once you’ve done that, everything in that directory (or any subdirectories under that directory) is considered to be in that Assembly Definition, and a separate DLL is created for each Assembly Definition. The exception is if you put another AD within that structure. For example, you could have an Assembly Definition in Stats Assembly-RPG-Stats, but suppose you also have an Editor folder in the Stats folder for a custom editor for the progression… you’d put an Assembly Definition there that is set to only be in the Editor, and not in any builds.

Now here’s the catch: Code in an Assembly Definition only has access to UnityEngine code unless you grant it access to other code. It’s not possible, however, for code in an AD to see code in Assembly-CSharp (any code not in an AD), but code in Assembly-CSharp can see any AD.

So lets assume that each directory/namespace in your game has it’s own AD. If one AD needs access to another AD, you have to edit the AD to add the AD you wish to include in the AD’s dependencies. This is a great way to enforce dependencies. If the AD doesn’t reference it, you can’t include it.

This also means that if you need to use things that are in packages (like Cinemachine, Newtonsoft, the new Input System, etc), you need to link those in your AD as well.

2 Likes

Great question by @Adam_Moore! Thanks for the quick explanation on how AD works in the UnityEngine @Brian_Trotter

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms