<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Claudio Grassi on Medium]]></title>
        <description><![CDATA[Stories by Claudio Grassi on Medium]]></description>
        <link>https://medium.com/@claudiograssi?source=rss-277e6541adfd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WIxFZUhdpQJHcJhFBx-eeQ.jpeg</url>
            <title>Stories by Claudio Grassi on Medium</title>
            <link>https://medium.com/@claudiograssi?source=rss-277e6541adfd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:52:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@claudiograssi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unity: Dynamic Asset Binding with Custom Attributes — Part 3, Rise of the Machines]]></title>
            <link>https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-3-rise-of-the-machines-945d65220264?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/945d65220264</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[game-design]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Wed, 23 Jul 2025 17:32:07 GMT</pubDate>
            <atom:updated>2025-07-23T20:28:54.752Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity: Dynamic Asset Binding with Custom Attributes — Part 3, Rise of the Machines</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8S67J-7uhJpvcD7JB5JMQ.png" /></figure><p>By now, you’ve probably read the previous two articles (<a href="https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-1-1412b3bdf6d0">Part 1</a>, <a href="https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-2-electric-boogaloo-d40d32f499e3">Part 2</a>) and are ready to take what you’ve learned and build something amazing on your own. But before you send me off into the cold, dark recesses of the internet, let me show you one final example of how this system can be put to work.</p><p>Previously, we used custom attributes to define gameplay actions and link them to their corresponding asset addresses. This allowed us to dynamically load AudioClips for our audio system using nothing but metadata.</p><p>Now, we’re going to use a very similar approach to load <strong>GameObject</strong> assets into our VFXController.</p><p>After tagging our <strong>VFX prefabs</strong> with the appropriate Addressable keys, we can be confident that the following code will take care of the rest:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwGJ5etybmelPW9Bj23Ulg.png" /></figure><p>We begin by creating our VFXController class, which (as usual) inherits from MonoBehaviour. Inside this class, we define two variables — but wait, what’s this? &quot;pool size&quot;?</p><p>That’s right, it’s time for the <strong>bonus round</strong>, and your prize is a quick chat about <strong>pooling </strong>— because there’s never a bad time to talk about good coding practices.</p><p>We define an int to control the size of our object pools at the start of the game. This gives us a handle on how many VFX prefabs we preload and reuse, helping us avoid unnecessary instantiations and reduce garbage collection overhead down the line.</p><p>The second variable works much like the one we used in the AudioFXController. It&#39;s a dictionary that stores references to our VFX prefabs, each wrapped inside Unity’s built-in object pooling system. These prefabs are mapped to Type keys, just like before, based on the values specified in our custom attributes.</p><p>Naturally, we set up our dictionary in Awake(), so our pools are ready before anything kicks off.</p><p>Next, we call the InitializePoolDictionary method, passing in our VFXEventAttribute as a parameter. I&#39;m doing this to keep the system simple, flexible, and easy to follow — especially for those seeing this pattern for the first time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaR5B30IFpSTl3NaPOQv3Q.png" /></figure><p>As before, we’ve got a block of code to look at — and I’ll walk you through exactly what it’s doing.</p><p>We start by scanning the current assembly to find all types tagged with our specified custom attribute — just like we did earlier in the AudioFXController. We also exclude any abstract classes, since we want only concrete implementations.</p><pre>var allActionTypes = Assembly.GetExecutingAssembly().GetTypes()<br> .Where(t =&gt; t.GetCustomAttribute(actionType) != null &amp;&amp; !t.IsAbstract);</pre><p>Next, we loop through each of these types, making sure to skip any that don’t meet our criteria:</p><pre> foreach (var type in allActionTypes)<br> {<br>   var attr = type.GetCustomAttribute&lt;ActionAssetAttribute&gt;();<br>   if (attr == null)<br>   {<br>     continue;<br>   }  <br>   if (!typeof(ICardAction).IsAssignableFrom(attr.ActionType))<br>   {<br>     continue;<br>   }<br>...<br><br>}</pre><p>We check to avoid null attribute references and ensure the associated action type implements our ICardAction interface — keeping our system safe and consistent.</p><p>We then use the metadata we just retrieved to load our asset asynchronously, waiting patiently until the asset is fully loaded before moving on:</p><pre>...<br> <br> string addressableKey = attr.AddressableKey;<br> var handle = Addressables.LoadAssetAsync&lt;GameObject&gt;(addressableKey);<br> await handle.Task;<br>...</pre><p>This lets Unity fetch the correct VFX prefab dynamically at runtime using the address we defined in our attribute.</p><p>Now, this part is new: once we confirm the asset loaded successfully, we create an object pool using the loaded prefab (handle.Result). Each pooled instance starts inactive, and when released, Unity’s Addressables system handles cleaning it up.</p><pre> if (handle.Status == AsyncOperationStatus.Succeeded)<br> {<br>   var pool = new ObjectPool&lt;UnityEngine.GameObject&gt;(<br>     () =&gt; Instantiate(handle.Result),<br>     go =&gt; go.SetActive(false),<br>     go =&gt; Addressables.ReleaseInstance(go),<br>   null,<br>   false,<br>   _poolSize<br>   );<br>   _poolDictionary[attr.ActionType] = pool;<br> }<br> else<br> {<br>   Debug.LogError($&quot;Failed to load VFX asset for {addressableKey}&quot;);<br> }</pre><p>We pass in the _poolSize to control how many instances the pool manages. We then add the pool to our dictionary, keyed by the action type from our attribute.</p><p>Finally, if the asset fails to load, we log an error to help us catch and diagnose any issues early. This ensures we’re aware if something goes wrong during the loading process.</p><p>At this point, we have a freshly populated object pool containing our desired VFX prefabs, all strongly linked to their respective ICardAction types via our dictionary.</p><p>The last thing to cover is how we actually use these pooled objects. Unity’s object pooling system makes this pretty straightforward, so we define two simple methods: one to retrieve (or “get”) an instance from the pool, and another to return it back when we’re done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sH4VY0PjOpdltnhG7N4YaQ.png" /></figure><p>These two methods should be pretty straightforward if you’ve been following along.</p><p>The <strong>GetObjectFromPool</strong> method takes an ICardAction instance, looks up the corresponding pool in our dictionary by the action’s type, and if found, calls the pool’s Get() method to fetch an available object. This lets us efficiently reuse VFX prefabs without constantly instantiating new ones.</p><p>The <strong>ReturnToPool</strong> method handles putting an object back into its correct pool. It first checks if the object isn’t null and if a pool exists for the given action type. If both checks pass, it deactivates the object and releases it back to the pool for later reuse.</p><p>And that’s it! You now have a self-populating VFX repository that can return pooled objects based on your specified action types. To see this in action, we can simply add a couple of lines to the PerformAction method of your ICardAction implementation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4p96AkENC39hQ6is6PUKQ.png" /></figure><p>In this example, PerformAction() grabs a pooled VFX GameObject based on the action’s type. If one’s available, it sets the VFX position to the card’s location and activates it. Then it plays the matching sound effect — all cleanly decoupled, fully dynamic, and ready to blow your mind. Holy smokes!</p><p>💡 <strong>Note:</strong> The lifecycle management of the VFX objects — like when to deactivate them and return them to the pool — should be handled elsewhere in your code to ensure efficient reuse and avoid leaks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*Y_l7fK7cfQvsuvGGPEWrWw.gif" /><figcaption>A quick example of the system at work</figcaption></figure><p><strong>If you’ve made it this far, congratulations… to ME!</strong><br>Turns out my ex was wrong — I’m not as boring as a cardboard box. I guess she never met a cat. But I digress.</p><p>You now have the tools to build some seriously slick systems in your own projects. With custom attributes, a bit of reflection, Unity’s Addressables and object pooling, you’ve got a setup that ties gameplay actions directly to their assets — without hardcoding anything, and without making a mess. Everything just hooks up automatically. Want to add more actions or effects later? Easy. The system scales with you, not against you. It’s clean, it’s dynamic, and honestly, kind of satisfying to watch in action.</p><p>Thanks for reading — hope you learned something useful. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=945d65220264" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity: Dynamic Asset Binding with Custom Attributes — Part 2, Electric Boogaloo]]></title>
            <link>https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-2-electric-boogaloo-d40d32f499e3?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40d32f499e3</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[game-design]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 17:32:31 GMT</pubDate>
            <atom:updated>2025-07-23T18:18:12.979Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity: Dynamic Asset Binding with Custom Attributes — Part 2, Electric Boogaloo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tesld8qX5GiBRGWCdbNgQ.png" /></figure><p>In <a href="https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-1-1412b3bdf6d0">Part 1</a>, we built the foundation of a flexible asset binding system using custom C# attributes. We created a base attribute class, ActionAssetAttribute, that allowed us to tag classes with metadata like the Type of action they relate to and the corresponding Addressables key. We then used that metadata to associate assets with gameplay events — such as VFX or SFX tied to card actions — without hardcoding every mapping manually.</p><p>We also introduced a simple ICardAction interface to represent gameplay logic like flipping a card, giving us a modular way to define what each action does, while keeping our asset binding decoupled and extensible.</p><p>All of that setup is just one half of the full picture.</p><p>In this article, we’ll bring the system to life using <strong>Reflection</strong> and Unity’s <strong>Addressables</strong> system. The result will be a runtime map that links gameplay actions to the correct assets — automatically, cleanly, and without fragile switch statements.</p><p>You know this reminds of the time my dog —</p><p>…What’s that? You don’t care?<br> Wow. Okay. Cool. Let’s just dive into the article then… <em>hater.</em></p><h3>Part 2.1 — The Audio Controller</h3><p>We’ll start by building out the <strong>Audio Controller</strong>, since it’s the most straightforward use case. Once we’ve got that working, we’ll follow it up with a <strong>VFX Controller</strong> to demonstrate how this system supports different asset types with minimal changes.</p><p>Before we dive in, let’s make sure we have the <strong>Addressables</strong> package installed via Unity’s Package Manager. Once that’s set up, select your <strong>AudioClip</strong> asset in the editor, check the <strong>Addressable</strong> box, and assign a key — this key will be used later to load the asset dynamically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*tPfgzoc99N-TzQFEW3lbtw.gif" /><figcaption>Make sure to double-check your spelling.</figcaption></figure><p>Now that our AudioClip is properly marked as an addressable, it’s time to move on to building the <strong>AudioFXController</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sun-PRdcxqOpq3A79NK-tg.png" /></figure><p>Okay, bear with me — there’s a bit to cover here, but I’ll walk through it almost line by line.</p><p>Let’s start with the elephant in the code:</p><pre>[RequireComponent(typeof(AudioSource))]</pre><p>This, as you’ve probably noticed, is a native Unity attribute. To cement the concept, this attribute applies to classes and ensures that a specified component — in this case, an AudioSource—is attached to the same GameObject as this MonoBehaviour. If it’s not already there, Unity automatically adds it. This guarantees that when our AudioFXController runs, it can safely rely on an AudioSource component being present.</p><p>Next, our AudioFXController class, which inherits from MonoBehaviour, declares two private variables:</p><pre>private AudioSource _sfxAudioSource;<br>private Dictionary&lt;Type, AudioClip&gt; _sfxDictionary = new();</pre><p>The first variable, _sfxAudioSource, will be assigned during the Awake() method using the classic GetComponent&lt;AudioSource&gt;() call. This links our controller to the AudioSource component Unity ensures is on the GameObject thanks to the [RequireComponent] attribute.</p><p>The second variable, _sfxDictionary, is a dictionary that will hold mappings between our action types (Type) and their corresponding audio clips (AudioClip). This dictionary is populated in the InitializeClipDictionary() method, which we’ll dive into shortly.</p><p>💡 A quick note about <strong>Reflection</strong> in C#: Reflection is a powerful feature that lets our code “look at itself” — meaning it can inspect its own types, methods, attributes, and metadata at runtime. This ability enables us to dynamically discover and act on classes and members based on conditions we specify, without hardcoding references.</p><p>The following method: InitializeClipDictionary() is where most of the magic happens.</p><pre>var typesWithSFXAttr = Assembly.GetExecutingAssembly()<br> .GetTypes()<br> .Where(t =&gt; t.GetCustomAttribute&lt;SFXActionAttribute&gt;() != null);</pre><p>After clearing our dictionary, we declare a local variable named typesWithSFXAttr. This variable will hold all the <strong>Types</strong> in our assembly that have the SFXActionAttribute.</p><p>Let’s break down this line step-by-step:</p><ul><li>First, we scan the currently executing assembly — which is essentially all the code that makes up our game at runtime.</li><li>We retrieve <em>all</em> the types defined there, which includes every MonoBehaviour, Player, Health, Pickup, and so on.</li><li>Then, using LINQ, we filter this list to only include the types that have our custom attribute applied. In other words, we keep only those types where the SFXActionAttribute is <strong>not null</strong>.</li></ul><p>This lets us dynamically discover all the relevant classes tagged with our attribute — without having to hardcode or manually list them anywhere.</p><p>This is reflection at work. By leveraging these metadata tags — our custom attributes — we’re able to inspect our own code at runtime and dynamically find exactly the classes we’re interested in. No manual lists, no hardcoded references — just clean, automatic discovery based on the information we’ve attached. Pretty neat, huh?</p><p>Once we have our collection of classes tagged with the custom attribute, we loop through each one to perform some additional filtering:</p><pre>foreach (var type in typesWithSFXAttr)<br> {<br>   var attr = type.GetCustomAttribute&lt;SFXActionAttribute&gt;();<br>   var actionType = attr.ActionType;<br>   if (!typeof(ICardAction).IsAssignableFrom(actionType))<br>   {<br>     Debug.LogWarning($&quot;Target type {actionType} does not implement ICardAction.&quot;);<br>     continue;<br>   }<br>...</pre><p>First, we retrieve the attribute instance and grab the stored ActionType we defined earlier in our classes. Then, we verify that this ActionType actually implements the ICardAction interface before proceeding. This helps us catch any mismatches early and keeps our system robust.</p><p>Finally, we make use of Unity’s Addressables system to dynamically load the tagged assets and insert them into our dictionary:</p><pre>...<br>   var clip = await Addressables.LoadAssetAsync&lt;AudioClip&gt;(attr.AddressableKey).Task;<br>   if (clip != null)<br>   {<br>     _sfxDictionary[actionType] = clip;<br>     Debug.Log($”Loaded SFX for {actionType.Name}: {clip.name}”);<br>   }<br>   else<br>   {<br>     Debug.LogError($”Failed to load SFX asset for {attr.AddressableKey}”);<br>   }<br> }</pre><p>Each clip is loaded asynchronously using await, pausing execution until the asset is ready. By calling LoadAssetAsync&lt;T&gt; and passing in the AddressableKey (which we provided earlier via our custom attribute), we’re asking Unity to go fetch that asset at runtime.</p><p>Once the loading is complete, we do a quick null check to verify success. If the asset is valid, we store it in our dictionary with the corresponding actionType as the key and the loaded AudioClip as the value.</p><p><strong>The big picture here — the real takeaway — is that by simply tagging classes and supplying a bit of metadata, we’ve created a system that can automatically discover and link two otherwise unrelated objects together at runtime.</strong> No hardcoded mappings. No messy setup logic. Just clean, extensible data-driven design.</p><p>The final piece of this simple example is how we actually use the data we’ve loaded:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__NobupN2xuTZ95aKLkeFw.png" /></figure><p>Whenever we want to play a sound effect tied to a gameplay action, we simply call PlaySFX(ICardAction action) and pass in the action instance. The method uses the action’s type to look up the matching AudioClip in our dictionary, and if it finds one, plays it using PlayOneShot.</p><p><strong>Clean. Dynamic. Decoupled.</strong> No switch statements. No manual mappings. Just runtime discovery doing what it does best.</p><p>To drive the point home, here’s what an ICardAction implementation might look like when taking advantage of the system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zNCD4F6buOEJRHsyoZqEA.png" /></figure><p>With this setup, the FlipCardAction doesn&#39;t need to know <em>what</em> sound to play — just that it should play one. The system takes care of the lookup and loading behind the scenes, using metadata we defined earlier. This keeps each action focused purely on its behavior, while still allowing for asset-driven flair.</p><p>Hopefully by now you have a solid sense of just how powerful and extensible this system can be. That’s the core idea: enabling objects to identify themselves to another system, and then having the appropriate response triggered based on that identity — all defined by <em>you</em>.</p><p>In <a href="https://tinyurl.com/ppue93js">Part 3</a>, we’ll complete our journey by applying this same system to the VFXController, showing how easily it scales to work with different asset types.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40d32f499e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity: Dynamic Asset Binding with Custom Attributes — Part 1]]></title>
            <link>https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-1-1412b3bdf6d0?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1412b3bdf6d0</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Mon, 21 Jul 2025 13:22:51 GMT</pubDate>
            <atom:updated>2025-07-22T20:45:52.805Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity: Dynamic Asset Binding with Custom Attributes — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-S5kocVdRwxNp5efn_xVQ.png" /></figure><p>That’s a mouthful, so let me explain:</p><p>You’ve probably already run into a situation where you need to link specific assets to specific actions in your game. Maybe you have AudioClips that should play when certain things happen — or a bunch of ParticleSystems that need to trigger with unique attacks.</p><p>Your first instinct might be to create a manager class, drop in all those assets manually (either in a list or one by one), and use a switch statement to return the right one when needed.</p><p>That works… until it doesn’t.</p><p>As your project grows, that manager becomes bloated, fragile, and hard to maintain. And suddenly, what started as a simple system becomes one more thing you have to fight with every time you want to add a new event.</p><p>In this article, I’ll show you how to use <strong>custom C# attributes</strong> and <strong>Unity Addressables</strong> to make a smarter system — one where your assets basically say, “Hey, I belong to this action,” and the game loads them automatically.</p><p>It’s not less code — in fact, it’s a bit more setup — but it’s a lot <strong>cleaner</strong>, <strong>safer</strong>, and <strong>more flexible</strong> in the long run.</p><h3>PART 1 — Custom Attributes:</h3><p>If you’re thinking <em>“I don’t know what attributes are,”</em> I’ve got good news: <strong>Yes, you do.</strong><br>You’ve almost certainly used them before without realizing it.</p><p>Do any of these look familiar?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*HRyvbQNZvB_-YZELR4yr6g.png" /></figure><p>Every one of these is a <strong>C# attribute</strong>.<br>They’re essentially little pieces of <strong>metadata </strong>you attach to your classes, fields, methods, or properties — and they let Unity (or any system) know something special about that piece of code.</p><p>The system we’re about to build uses <strong>custom attributes</strong> — those little metadata tags — to help our game automatically figure out <strong>what assets to load and when</strong>.</p><p>In other words, instead of manually wiring everything together with big switch statements or hardcoded references, we’ll <strong>let the code “discover” the right assets at runtime</strong> based on how we’ve tagged things.</p><p>To do that, the first step is to <strong>create our own custom attribute</strong> — which is really just defining the behavior for a new tag that we can attach to classes, in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1oVqh4wo84iFt3Jcvr_ZA.png" /></figure><p>We did it!<br>What’s that? You want an explanation of what this all means? Well, okay — if you insist.</p><p>Let’s break it down.</p><p>The very first line:</p><pre>[AttributeUsage(AttributeTargets.Class)]</pre><p>…is actually an attribute <em>itself</em>! It tells the compiler where our custom attribute is allowed to be used. In this case, it specifies that our ActionAssetAttribute can <strong>only</strong> be applied to <strong>classes</strong>.</p><p>To put it in context:<br>You’ve probably used [SerializeField] before — but if you tried placing it on a class or method, Unity or your compiler would complain. That’s because [SerializeField] is only valid on <strong>fields</strong>.</p><p>Similarly, [ActionAsset] will only be valid when used to decorate <strong>classes</strong>, because of this [AttributeUsage] declaration.</p><p>Next, we declare the class ActionAssetAttribute, which inherits from the built-in Attribute</p><pre>public class ActionAssetAttribute : Attribute</pre><p><strong>Important:</strong> Even though the class is named ActionAssetAttribute, when you use it in code, you only write [ActionAsset].<br> This is because C# automatically allows you to omit the &quot;Attribute&quot; suffix when applying attributes.<br>Think of &quot;Attribute&quot; as a hidden postfix: it&#39;s required in the class declaration to follow C# conventions, but when using the attribute in your code, you can leave it out. This keeps usage clean and consistent.</p><p>The next part is the class body itself:</p><pre><br> public Type ActionType { get; }<br> public string AddressableKey { get; }<br> public ActionAssetAttribute(Type type, string key)<br> {<br>   ActionType = type;<br>   AddressableKey = key;<br> }</pre><p>This part is pretty straightforward. We’re defining two properties that we’ll make use of later:</p><ul><li>ActionType will store the <strong>type of action</strong> that this asset is associated with.</li><li>AddressableKey is a <strong>string key</strong> we’ll use to find the asset in Unity’s Addressables system.</li></ul><p>Then, the constructor just takes in those two values (type and key) when the attribute is used, and stores them in the properties.</p><p>At this point, you might be wondering:</p><blockquote><em>“Why go through the trouble of using attributes at all? Why not just create classes like this and manually set things up in some initialization method?”</em></blockquote><p>Great question — and here’s the short answer: <strong>you absolutely could.</strong><br>But doing it that way often means writing <strong>a lot of manual, hardcoded setup</strong> logic every time you add a new asset, action type, or link between them.</p><p>What we’re doing instead is using <strong>attributes as metadata</strong> — letting us tag classes with information and later discover and load those tagged assets dynamically at runtime.<br>This makes the system <strong>more scalable</strong>, <strong>less error-prone</strong>, and <strong>far easier to expand</strong> as your project grows.</p><p>So that’s the whole of the custom Attribute — but we’re only getting started.</p><h3>Part 2 — Concrete Classes with Custom Attributes:</h3><p>Now that we’ve defined our ActionAsset attribute, it’s time to actually use it.</p><p>For this example, we’ll create two concrete classes: one for a particle system VFX and one for an audio clip. These represent common types of assets you might want to associate with gameplay events in your project — like firing off a visual explosion or playing a sound when something happens.<br>These classes will act as <strong>containers or wrappers</strong> for your actual assets, and the attribute will tell our system how to treat them when it runs.</p><p>We can now extend ActionAssetAttribute to define more specific asset categories. For example, here are two subclasses for tagging VFX and SFX assets separately. Let’s see how that looks in code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_KiySYboqW67cEw9TN-KQ.png" /></figure><p>Since both VFXActionAttribute and SFXActionAttribute extend our original ActionAssetAttribute, they can now be used just like any other custom attribute. This makes our system a bit more modular and scalable.</p><p>When we apply one of these attributes, the constructor from the base class is automatically called behind the scenes, and the properties we defined earlier (ActionType and AddressableKey) are set using the values passed in.</p><p>This setup allows us to categorize different types of assets cleanly, while keeping the reflection-based loading system generic and centralized.</p><p>But I promised you concrete classes, so without further ado, here are two example declarations that put our shiny new attributes to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ob8mPyghjzjMuO_51aFs3A.png" /></figure><p>Tada!</p><blockquote>“But broooo…these concrete implementations are empty! what do they even do?!”</blockquote><p>Ah, my friends, they’re doing exactly what they’re meant to — connecting data together! Oh-my!</p><p>Let’s break one of these down:<br>We start by tagging our new class with the [VFXAction] attribute. The sharp-eyed among you will notice we’re passing two parameters here—just like calling a regular constructor:</p><pre>[VFXAction(typeof(FlipCardAction), “VFX/FlipAction”)]</pre><p>The first parameter is the Type of event we want to associate — in this case, FlipCardAction. I’ll show you what that looks like shortly.<br> The second parameter — and I’ll admit this is the flimsiest part of the system — is the string key used to look up the addressable asset. This key tells Unity’s Addressables system which asset to load at runtime. While it requires a bit of manual setup, it keeps things flexible, letting you swap assets without changing any code. Just be sure the key matches the addressable asset’s address exactly.</p><p>The rest of the class isn’t necessary for our current use case. Essentially, it just creates an object that’s been tagged and holds the information we need.</p><h3>Part 2.5 — What the heck is a FlipAction, anyway?:</h3><p>Before we go any further, you might be wondering what exactly a FlipCardAction (or any other action) looks like and why it matters in this system. Let’s take a quick peek under the hood to see how these classes fit into the bigger picture.</p><p>Since this system is built around a card game example, I defined a simple interface to represent any card-related action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*9M9jF63UIZ8fWQmzWhdm6A.png" /></figure><p>All of my card actions implement this interface. This gives me a consistent contract to work with, and it also helps refine lookups when pairing action types with assets using our custom attributes.</p><p>Here’s a concrete example — a FlipCardAction that implements ICardAction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FX55FTctg_OXjr2DScwg6Q.png" /></figure><p>There’s nothing mystical about this class — it simply represents an action we can instantiate to perform whatever behavior our little hearts desire. In this case, some fantastic card flipping, eye-melting, mind-blowing animations. Trust me, bro.</p><p>The important takeaway is that this concrete implementation is exactly the Type we passed as a parameter in our custom attribute tagging the FlipActionVFX and FlipActionSFXclasses.</p><p>💡 <strong>Note:</strong> In this article, <em>“actions”</em> refer to the concrete logic classes that execute in response to gameplay triggers — such as clicks. While I use the term <em>action</em> throughout, these are conceptually closer to a <strong>Command Pattern</strong> implementation.</p><p>This is a good spot to end for Part 1! We’ve laid the groundwork by building our custom attributes and tying them to some example classes. In the next part, we’ll dive into reflection — how to actually find these tagged classes at runtime, load your assets dynamically with Addressables, and see this system come to life with real examples. Stay tuned —<a href="https://claudiograssi.medium.com/unity-dynamic-asset-binding-with-custom-attributes-part-2-electric-boogaloo-d40d32f499e3"> Part 2</a> is coming soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1412b3bdf6d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UNITY 3D REPLICANICS: Replicating Steam’s Collectible Card Display Mechanic — Part III]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-iii-85e210cd1495?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/810/1*SG51wBMzjrVQ3aaoy4UH3g.png" width="810"></a></p><p class="medium-feed-snippet">Replicanic /&#x2C8;r&#x25B;pl&#x26A;kan&#x26A;k/: A blend of replicate and mechanic. The term aims to define the act of duplicating mechanics from any commercial&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-iii-85e210cd1495?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-iii-85e210cd1495?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e210cd1495</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 18:33:02 GMT</pubDate>
            <atom:updated>2021-11-12T18:33:02.550Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[UNITY 3D REPLICANICS: Replicating Steam’s Collectible Card Display Mechanic — Part II]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-ii-b97451fcba10?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/810/1*jB0Uueqiz7Bm2YG58teeLg.png" width="810"></a></p><p class="medium-feed-snippet">Replicanic /&#x2C8;r&#x25B;pl&#x26A;kan&#x26A;k/: A blend of replicate and mechanic. The term aims to define the act of duplicating mechanics from any commercial&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-ii-b97451fcba10?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-ii-b97451fcba10?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/b97451fcba10</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Thu, 11 Nov 2021 18:32:59 GMT</pubDate>
            <atom:updated>2021-11-11T18:44:20.796Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[UNITY 3D REPLICANICS: Replicating Steam’s Collectible Card Display Mechanic— Part I]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-i-259792c2a407?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/810/1*nFIT_rJCpPskwNJY2keq5Q.png" width="810"></a></p><p class="medium-feed-snippet">Replicanic /&#x2C8;r&#x25B;pl&#x26A;kan&#x26A;k/: A blend of replicate and mechanic. The term aims to define the act of duplicating mechanics from any commercial&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-i-259792c2a407?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity-3d-replicanics-replicating-steams-collectible-card-display-mechanic-part-i-259792c2a407?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/259792c2a407</guid>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 17:58:28 GMT</pubDate>
            <atom:updated>2021-11-11T22:40:01.296Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Unity2D Devlog 21 — Never Miss Again!]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity2d-devlog-21-never-miss-again-c364b5e367d0?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/600/1*uzpRNVxVQrZjT3Blz8qZOw.gif" width="600"></a></p><p class="medium-feed-snippet">Lately, I&#x2019;ve been on a rollercoaster ride of balancing and counterbalancing game mechanics.</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity2d-devlog-21-never-miss-again-c364b5e367d0?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity2d-devlog-21-never-miss-again-c364b5e367d0?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c364b5e367d0</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 16:32:55 GMT</pubDate>
            <atom:updated>2021-07-12T16:32:55.376Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Unity2D Devlog 20 — Dodge This, You Filthy Casual]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity2d-devlog-20-dodge-this-you-filthy-casual-55a21c9eb644?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/600/1*sRp-o52xgq_afDZQe2uvjQ.gif" width="600"></a></p><p class="medium-feed-snippet">With one exception, all enemies follow a linear vertical path. This movement makes it simple for the Player to shoot them down accurately&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity2d-devlog-20-dodge-this-you-filthy-casual-55a21c9eb644?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity2d-devlog-20-dodge-this-you-filthy-casual-55a21c9eb644?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/55a21c9eb644</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[learn-to-code]]></category>
            <category><![CDATA[game-design]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Thu, 08 Jul 2021 16:33:24 GMT</pubDate>
            <atom:updated>2021-07-08T16:33:24.650Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Unity2D Devlog 19 — Beating Them To It]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity2d-devlog-19-beating-them-to-it-a50b87a329ae?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/600/1*gRXsQPEiW3NM_kb7yLGh3A.gif" width="600"></a></p><p class="medium-feed-snippet">In my last DevLog, I wrote about giving enemies the ability to destroy power-ups. I realized that the result might have been too powerful&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity2d-devlog-19-beating-them-to-it-a50b87a329ae?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity2d-devlog-19-beating-them-to-it-a50b87a329ae?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a50b87a329ae</guid>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-design]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Wed, 07 Jul 2021 16:32:19 GMT</pubDate>
            <atom:updated>2021-07-07T16:32:19.977Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Unity2D Devlog 18 — Now You See It, Now You Don’t]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://claudiograssi.medium.com/unity2d-devlog-18-now-you-see-it-now-you-dont-4ec756c19a9e?source=rss-277e6541adfd------2"><img src="https://cdn-images-1.medium.com/max/600/1*QtHjaCocvFHgyasD30dIDw.gif" width="600"></a></p><p class="medium-feed-snippet">PowerUps can activate powerful weapons, be used to reload ammunition, and heal damage. The Player must take advantage of them to survive&#x2026;</p><p class="medium-feed-link"><a href="https://claudiograssi.medium.com/unity2d-devlog-18-now-you-see-it-now-you-dont-4ec756c19a9e?source=rss-277e6541adfd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://claudiograssi.medium.com/unity2d-devlog-18-now-you-see-it-now-you-dont-4ec756c19a9e?source=rss-277e6541adfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ec756c19a9e</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Claudio Grassi]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 16:31:05 GMT</pubDate>
            <atom:updated>2021-07-06T16:31:05.847Z</atom:updated>
        </item>
    </channel>
</rss>