# Assembly Definitions

<p class="callout warning">Assembly Definitions can be overwhelming for beginners, but should be essential knowledge for developers of widely used prefabs made with UdonSharp.</p>

<p class="callout info">I have just released a new Unity Editor extension for automating assembly definition generation: [Experimental Automatic Assembly Definition Generator by Varneon \| GitHub](https://github.com/Varneon/AssemblyDefinitionGenerator "https://github.com/Varneon/AssemblyDefinitionGenerator")</p>

### <span style="color: #3598db;">What are assembly definitions?</span>

<p class="callout info">Assembly Definitions and Assembly References are assets that you can create to organize your <span class="tooltip">scripts </span>into assemblies.</p>

<p class="callout info">[https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html)</p>

---

### <span style="color: #3598db;">Why use assembly definitions?</span>

<p class="callout success">Usage of assembly definitions promotes modularity and assists with declaring a clear scope for the dependencies</p>

<p class="callout success">Assembly definitions support Define Constraints: only compile the assembly if specific Scripting Define Symbol is present (e.g. if you only want the assembly to compile if the symbol "UDONSHARP" is present, you can add it as a constraint)</p>

---

### <span style="color: #3598db;">How to use assembly definitions with U# 1.x?</span>

<p class="callout info">U# requires a custom U# Assembly Definition to be present alongside with the main Assembly Definition when U# scripts are in said assembly</p>

<details id="bkmrk-1%29-create-assembly-d"><summary>1) Create Assembly Definition</summary>

[![image-1661019953736.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661019953736.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661019953736.png)

<p class="callout info">Name the Assembly Definition file clearly to indicate the developer and the project (Recommended to use similar format to namespaces)</p>

[![image-1661020045130.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661020045130.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661020045130.png)

<p class="callout info">Right after creating the assembly, you may notice errors appearing in your console, this is because the assemblies of the scripts that our scripts are referencing, aren't defined in the assembly definition</p>

[![image-1661020225203.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661020225203.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661020225203.png)

</details><details id="bkmrk-2%29-define-the-assemb"><summary>2) Define the assembly references</summary>

<p class="callout success">Adding **UdonSharp.Runtime** assembly as a reference allows us to reference the scripts contained in that assembly from our own scripts</p>

<p class="callout info">If you need to access common VRChat's classes, such as VRCPickup or UdonBehaviour, other common assemblies to reference are **VRC.Udon** and **VRC.SDK3**</p>

<p class="callout warning">**Disabling the option "Use GUIDs" is recommended, since the GUIDs may change over time** </p>

[![image-1661020467667.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661020467667.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661020467667.png)

<p class="callout info">Right after clicking "Apply" on the assembly definition the scripts will attempt to compile, and you will most likely see the following error in the console. We will fix this next.</p>

[![image-1661021023795.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661021023795.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661021023795.png)

</details><details id="bkmrk-3%29-create-u%23-assembl"><summary>3) Create U# Assembly Definition</summary>

[![image-1661021108017.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661021108017.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661021108017.png)

<p class="callout danger">Make sure to name the U# Assembly Definition file identically to the main assembly definition's name!</p>

[![image-1661021161988.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661021161988.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661021161988.png)

<p class="callout info">As the last step, assign the main assembly definition as the "Source Assembly" on the U# assembly definition</p>

[![image-1661021296415.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661021296415.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661021296415.png)

<p class="callout success">Now all of your UdonSharpBehaviours should compile successfully and you can continue the development</p>

<p class="callout info">If UdonSharp still throws an error related to the scripts not being a part of a U# assembly, try reimporting the U# assets and scripts in the folder.</p>

[![image-1661021928118.png](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/scaled-1680-/image-1661021928118.png)](https://vrclibrary.com/wiki/uploads/images/gallery/2022-08/image-1661021928118.png)

</details>