Assembly Definitions, Explained | Unity Tutorial

Sdílet
Vložit
  • čas přidán 7. 07. 2024
  • This week you can learn about Assembly Definitions, which are a Unity Construct to create C# Projects within your game's "Solution". This allows Unity to determine which scripts needs to be compiled after making a change, instead of naively recompiling the entire project. Compiling fewer scripts lets you get back into the editor faster after making code changes!
    💸 Ongoing sales 💸
    ⚫ Check out the latest Humble Bundles www.humblebundle.com/software...
    ⚫ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! assetstore.unity.com/publishe...
    ⚫ Save up to 50% on NEW Assets: assetstore.unity.com/?new_sal...
    👨‍💻 As always, all code from this video is available on GitHub (this time via the Gun Scriptable Object Series Repo): github.com/llamacademy/script...
    📚 Resources:
    ⚫ Namespaces Explanation: • Namespaces in C# by Un...
    ⚫ Assembly Definition Manual: docs.unity3d.com/Manual/Scrip...
    ⚫ Assembly Definition Properties: docs.unity3d.com/Manual/class...
    ⚫ Assembly Definitions & Packages: docs.unity3d.com/Manual/cus-a...
    ❤ Believe in LlamAcademy's mission and have received value from the videos? Become a Patreon Supporter or CZcams Member:
    ⚫ Patreon: / llamacademy
    ⚫ CZcams Member: / @llamacademy or click the Join button on any video
    📱 Let's stay connected
    CZcams: / llamacademy
    Patreon: / llamacademy
    Facebook: / llamacademyofficial
    Twitter: / thellamacademy
    TikTok: / llamacademy
    Instagram: / llamacademy
    ----
    Most tutorials come from knowledge gained making survival.llama.software Llama Survival - a top-down zombie survival shooter for Android and iOS.
    I also have some Unity Assets: assetstore.unity.com/publishe...
    Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
    #unitytutorial #tutorialtuesday #gamedev #tutorial #unity #llamacademy #gamedevelopment
    Chapters:
    00:00 Topic Introduction
    00:52 How Unity works without Assembly Definitions & the use case for them
    01:30 How I split up Assembly Definitions
    01:59 Examples from the Gun Scriptable Object Series
    02:55 Creating an Assembly Definition File & Common Option Overview
    04:37 More Advanced Features You'll Probably Never Use
    05:10 Why it's Important for Asset Store Packages
    05:40 Final Thoughts & Support LlamAcademy

Komentáře • 26

  • @1x5x7
    @1x5x7 Před rokem +9

    I'm just gonna pop it in here, you are such an amazing creator and helped me through so many things with in-depth explanations. Keep the high quality work up!

  • @ericevanshub
    @ericevanshub Před rokem +5

    Very helpful! I'd like to see a part 2 of this with the more advanced assembly def features you find useful, such as multiple folders & symbols. Maybe discussing tests in a separate assembly, etc.

  • @castlecodersltd
    @castlecodersltd Před rokem +1

    Thanks for this one. I was starting to get frustrated how long it took to compile, this will really help my project. Thank you ☺

  • @derbabonennt8876
    @derbabonennt8876 Před rokem +2

    Thank for clearing this topic - always thought it was more complicated❤

  • @thyroid99
    @thyroid99 Před rokem +1

    Great content! Please keep it up!

  • @schultenmedia9827
    @schultenmedia9827 Před rokem +1

    Great video !!

  • @durvids474
    @durvids474 Před rokem +1

    Yes, you!! Thanks for the awesome video!!

  • @AndresCamiloUrregoRestrepo
    @AndresCamiloUrregoRestrepo Před 11 měsíci +1

    This and the assembly references once saved a project that I had to fix for my job :p

  • @TricoliciSerghei
    @TricoliciSerghei Před 8 měsíci +1

    Very nice video, thank you so much.

  • @polylob9729
    @polylob9729 Před rokem

    I'm not sure if this is the right place, but I'm trying to add a symbol preprocessor to my GitHub package, for example, #define MY_PACKAGE. So, I can have pieces of code that can only be compiled if the package is downloaded by using #if MY_PACKAGE. Normally, everything should be grayed out unless I download the package. Is it possible to do something in the assembly of the package to achieve this?

  • @sqdtnz
    @sqdtnz Před rokem +3

    In terms of architecture it's quite tricky though, I tried implementing it in an existing (medium sized) project, and there were just quite a few annoying circular references (bad practices in my code), that were hard to solve. Best is to use this right from the start I think.

    • @LlamAcademy
      @LlamAcademy  Před rokem +2

      I agree - it can be quite challenging to retroactively organize a project if there was little or no discipline in place at the start.

  • @davidbone2295
    @davidbone2295 Před rokem

    great video, just thinking what if you do need circular reference!! what would be the best route ?

    • @LlamAcademy
      @LlamAcademy  Před rokem

      Generally speaking, that’s indicative of a design issue in your packaging. I would either keep the classes that are dependent on each other in the same asmdef because the code is coupled, or refactor the code to not be dependent.

  • @TechDunk
    @TechDunk Před 11 měsíci

    I want to use assembly definitions from the start in my latest project, to make sure the project stays reasonably snappy.
    I got it working up until I utilized my custom attributes. Here everything works in the inspector, since the attributes reference editor code I have to make another asm def for them only included in the editor.
    This works great in editor, but when I start building my project I get errors that the custom attribute namespaces cannot be found. When I enable the asm def for all platforms I get errors that the custom attributes reference editor code, not allowing me to build.

    • @LlamAcademy
      @LlamAcademy  Před 11 měsíci

      Hmm.... I think Custom Attributes have to be included in the primary ASMDef file. Things like custom editors and Property Drawers can be moved to an editor assembly, but attributes need to remain in the full build. This is kind of weird, but you can see even [AddComponentMenu] is in the UnityEngine, not UnityEditor namespace.

    • @TechDunk
      @TechDunk Před 11 měsíci

      @@LlamAcademy thanks! Had to split up the property drawer and attribute yes!

  • @bluzenkk
    @bluzenkk Před rokem +1

    can you tell me more about the "Define Constraints" section, i'm still not clear what is it and how to use it. when you say "Unity android has to be define for this to be compiled" what exactly does that mean....if this sentense mean it only compiles when in android, isn't that cover at the Exclude Platform section below where you can check or uncheck the Android?

    • @LlamAcademy
      @LlamAcademy  Před rokem

      UNITY_ANDROID is a C# define symbol (learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives ) that Unity adds when the Android platform is enabled. Many libraries define custom symbols like this to tell if some feature is enabled, or if the library exists. Mirror, the networking asset, is a good example that defines the symbol "MIRROR" when it is imported. You can find the ones any assets add in the Project Settings > Player > Other Settings > Script Compilation. If this is blank then you only have whatever Unity adds based on your Unity version, target platform, etc...
      A real life example is I have some networking chat systems that support both Mirror and the Unity HLAPI. I check which one is active by these define symbols and do something different based on which one is in use. I could go one step further and have an assembly for Mirror code and an assembly for the HLAPI code that would only compile if Mirror is added to the project, or the HLAPI is added to the project.
      You are right, by defining the platform as Android / iOS or whatever, it adds some scripting define symbols such as UNITY_ANDROID and UNITY_IOS. You can get the same outcome by including/excluding the target platform in the section below. I hope my example above helps clear up a little bit some other use cases for using the define symbols.

    • @bluzenkk
      @bluzenkk Před rokem

      @@LlamAcademy i didn't understand what you meant at first until i read the Mirror and HLAPI example. Thanks for the extensive explaination!

  • @bishoyfahim2266
    @bishoyfahim2266 Před rokem

    great content but when gun-system part 8 ?

  • @blitzgrims3758
    @blitzgrims3758 Před rokem

    I just found out this channel I want to know how to make a script to make ai flank (shooting game) it would be great to know