<?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 Abdullah on Medium]]></title>
        <description><![CDATA[Stories by Abdullah on Medium]]></description>
        <link>https://medium.com/@abdullahabdelati_46671?source=rss-1006694e725e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mR1M0jj6ggz_O8tsi4cnXg.jpeg</url>
            <title>Stories by Abdullah on Medium</title>
            <link>https://medium.com/@abdullahabdelati_46671?source=rss-1006694e725e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:17:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdullahabdelati_46671/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[UniTask vs Coroutine]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/unitask-vs-coroutine-b562b0a1685e?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b562b0a1685e</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[coroutine]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Wed, 15 Jul 2026 14:58:24 GMT</pubDate>
            <atom:updated>2026-07-15T15:12:45.648Z</atom:updated>
            <content:encoded><![CDATA[<p><em>UniTask can do almost exactly what a Coroutine does but why is UniTask more efficient? Let’s find out.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuPgfxHCSV9z9qIg8Onh-A.png" /></figure><p>Under the hood, the difference in Garbage Collection (GC) between Unity Coroutines and UniTask comes down to <strong>Heap Allocation vs Struct Pooling</strong>.</p><p>Here is exactly what happens in memory during their execution lifecycles.</p><h3>1. Unity Coroutines</h3><p>Every time we call StartCoroutine(MyCoroutine()):</p><ul><li><strong>State Machine Allocation:</strong> The C# compiler generates a hidden class behind the scenes to track the IEnumerator state. Calling the method instantiates this class on the <strong>heap</strong> (GC).</li><li><strong>Native Wrapper Allocation:</strong> Unity’s native engine creates a UnityEngine.Coroutine instance to manage the tracking lifecycle within the player loop (GC).</li><li><strong>Yield Instruction Allocation:</strong> Writing yield return new WaitForSeconds(1f); instantiates a new object on the <strong>heap</strong> every time this line executes (GC), unless you manually cache it.</li></ul><pre>void Start() {<br>    StartCoroutine(WaitRoutine()); // Triggers Allocations 1 &amp; 2<br>}</pre><pre>IEnumerator WaitRoutine() {<br>    yield return new WaitForSeconds(1f); // Triggers Allocation 3<br>    Debug.Log(&quot;Done&quot;);<br>}</pre><h3>2. UniTask</h3><p>When you invoke an async UniTask method:</p><ul><li><strong>Value Type Structs:</strong> UniTask and UniTask&lt;T&gt; are implemented as <strong>structs</strong> (value types). They live on the stack or inline within the state machine, causing zero allocation.</li><li><strong>Automated State Machine Pooling:</strong> The C# compiler still creates an async state machine. However, UniTask implements custom async method builders (AsyncUniTaskMethodBuilder). Instead of allocating a heap object for every run, UniTask retrieves an execution runner from an internal <strong>Object Pool</strong> (TaskPool&lt;T&gt;).</li><li><strong>Recycling on Completion:</strong> When the await operation finishes, the backing engine object resets its fields and returns itself directly back to the pool for reuse. No objects are left abandoned on the heap for the GC to clean up.</li></ul><pre>void Start() {<br>    WaitTask().Forget(); // 0 Allocations<br>}</pre><pre>async UniTask WaitTask() {<br>    await UniTask.Delay(1000); // 0 Allocations<br>    Debug.Log(&quot;Done&quot;);<br>}</pre><h4>GC isn’t the only performance issue with Coroutines.</h4><h3>1. The Managed vs Native Bridge Overhead</h3><ul><li><strong>The Coroutine Problem:</strong> Coroutines are driven by Unity’s C++ core. Every single frame, the C++ engine has to cross the “managed to native bridge” to call MoveNext() on your C# Coroutine. Crossing this bridge thousands of times a frame is computationally expensive.</li><li><strong>The UniTask Solution:</strong> UniTask runs entirely in managed C# space. It hooks into the Unity PlayerLoop just once, and handles all the timing and updates entirely in C#, avoiding the bridge overhead completely.</li></ul><h3>2. Try/Catch Blocks and Exception Handling</h3><ul><li><strong>The Coroutine Problem:</strong> You cannot wrap a yield return inside a try/catch block. If something goes wrong inside a Coroutine, it fails silently or breaks the flow, making debugging a nightmare.</li><li><strong>The UniTask Solution:</strong> Because it uses standard C# async/await, you can use standard try/catch/finally blocks exactly as you would in normal programming.</li></ul><h3>3. Cancellation</h3><ul><li><strong>The Coroutine Problem:</strong> Stopping a coroutine requires storing a reference to it and calling StopCoroutine(routine), which can be error-prone if the object is destroyed.</li><li><strong>The UniTask Solution:</strong> UniTask heavily relies on standard C# CancellationToken. You can pass a token to cancel tasks gracefully, and UniTask even provides extensions like .GetCancellationTokenOnDestroy() which automatically cancels the task when the GameObject dies, preventing null reference exceptions.</li></ul><h3>Conclusion: Is it time to make the switch?</h3><p>In summary, while Unity Coroutines have served us well for years, UniTask is the clear modern successor. By leveraging value type structs and object pooling, it effectively eliminates the Garbage Collection spikes that cause frame drops.</p><p>Combine that zero allocation architecture with the removal of native bridge overhead, robust try/catch exception handling, and built-in cancellation, and UniTask becomes an absolute must have for any performance conscious Unity project. If you haven&#39;t made the switch yet, there is no better time than now to start modernizing your codebase.</p><p>Thanks so much for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b562b0a1685e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to DOD (Data Oriented Design)]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/introduction-to-dod-data-oriented-design-72315fc22d95?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/72315fc22d95</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[data-oriented-design]]></category>
            <category><![CDATA[cpu]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 09:39:37 GMT</pubDate>
            <atom:updated>2026-06-13T15:13:09.424Z</atom:updated>
            <content:encoded><![CDATA[<p>DOD solves many architectural problems, and reducing <strong>cache misses</strong> to <strong>improve performance</strong> is one of its biggest advantages. By grouping data contiguously, the <strong>CPU</strong> can process large quantities of information without constantly querying main memory (which causes a cache miss). On the other hand, OOP can cause frequent cache misses because it groups data based on object relationships. This forces the CPU to constantly wait while retrieving data from main memory, leading to wasted cache space.</p><p>For example, if we have a particle that needs to move, the standard Object-Oriented code would look something like this:</p><pre>class ParticleController<br>{<br>    Vector3 m_position;<br>    Vector3 m_velocity;<br>    Color m_tint;<br>    float m_remainingLife;<br><br>    void Move(float deltaTime)<br>    {<br>        m_position += m_velocity * deltaTime;<br>    }<br>}</pre><p><strong>So, what happens under the hood?</strong></p><ol><li>CPU must first fetch m_position and m_velocity from main memory.</li><li>Because the CPU fetches memory in 64-byte blocks (cache lines), it is forced to pull the entire ParticleController object into the L1 Cache. This drags m_tint and m_remainingLife into the ultra-fast memory, polluting the cache with useless data.</li><li>Now that the data is cached, the CPU loads the current position, velocity, and deltaTime into its working <strong>registers</strong>.</li><li>The CPU multiplies velocity by deltaTime and stores the intermediate result in a register.</li><li>Finally, it adds that result to the original position to complete the movement.</li></ol><p>Now, CPUs can execute trillions of instructions per second, but here, that is entirely wasted on waiting. This severe delay is known as a cache miss, and it is a massive performance killer.</p><p>Once the data block finally arrives, the CPU can calculate that single particle. But because that 64-byte chunk of memory was polluted with useless data like m_tint and m_remainingLife, there was no room left to pull in the next particle. So, when the loop moves to particle number two, the CPU realizes the data is scattered somewhere else in RAM, and it has to stop and wait all over again. Because of how OOP scatters objects on the heap, the CPU will repeat this agonizing waiting process for every single particle, every single frame.</p><h4>The CPU Cache</h4><p>Simply put, the CPU cache is another type of ultra fast memory that lives directly on the CPU die. Modern CPUs have multiple cores, and each core typically has its own private L1 and L2 caches, along with a much larger L3 cache that is shared across all the cores.</p><p>So, if we can structure our code to keep our data packed inside these caches, we will see a massive performance boost in our games because we are reducing <strong>cache misses</strong>. To understand why, we have to look at the speed of the memory itself. The L1 cache is the absolute fastest among them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*OP8fCJdO-99dRgpz9qTlYw.png" /></figure><p>Memory Access Speeds (Approximate)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*dT7fca6hCZr2388h2oJVMQ.png" /></figure><blockquote><strong><em>Hint: Cache Prediction</em></strong><em> Your CPU doesn’t just wait around, it actively tries to guess what data your program will need next. If it guesses correctly, it pre-loads that data into the cache ahead of time. </em><strong><em>Data Oriented Design</em></strong><em> takes full advantage of this. By organizing your data in predictable, continuous lines, you guarantee the CPU can successfully predict and pre-load your future data before your code even asks for it.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*QwSQo4iFIytzQWenfx5OLA.png" /></figure><p>So, returning to our example, we can illustrate how the particle’s data fits into a single cache line like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*aoFa4Wa3zE_hI1gpQaHnzg.png" /></figure><h3>The Problem with OOP at Scale</h3><p>What happens when we load up our 2,000 circle particles for our game?</p><p>In standard OOP, we use an array of objects: ParticleController[] particles = new ParticleController[2000];</p><p>Because a C# class is a Reference Type, this array doesn&#39;t hold tightly packed data. It only holds memory addresses (pointers) pointing to objects scattered randomly across the heap.</p><p>When the CPU loops through this scattered array, two things ruin our performance:</p><ol><li><strong>The Prefetcher Fails:</strong> Without a linear pattern, the CPU cannot guess where the next particle is located, making cache prediction useless.</li><li><strong>Cache Pollution Multiplies:</strong> When the CPU finally finds a particle, it drags the useless data (m_tint, m_remainingLife) into the cache line again, leaving no room for the next particle.</li></ol><h4>The Solution:</h4><p>So instead of grouping the data in objects, we are going to place all the data in arrays.</p><pre>public class ParticleData<br>{<br>    // Data is isolated by its usage, not its object<br>    public Vector3[] Positions;<br>    public Vector3[] Velocities;<br>    public Color[] Tints;<br>    public float[] RemainingLives;<br>}<br><br>public class ParticleSystemManager<br>{<br>    public void UpdatePositions(ParticleData data, float deltaTime)<br>    {<br>        int count = data.Positions.Length; <br>        <br>        for (int i = 0; i &lt; count; i++)<br>        {<br>            data.Positions[i] += data.Velocities[i] * deltaTime;<br>        }<br>    }<br>}</pre><p>When our CPU processes the UpdatePositions() function, it will do the following:</p><p><strong>1.</strong> When the CPU reaches out to RAM to grab Positions[0], it still pulls back a 64-byte cache line. But because our array is tightly packed, it doesn&#39;t drag any useless Tints or RemainingLives along with it. If a Vector3 is 12 bytes, a single cache fetch pulls in exactly five continuous particle positions. Every single byte in that cache line is pure, usable math data.</p><p><strong>2. </strong>Because the for loop iterates sequentially through contiguous arrays (i = 0, 1, 2...), the hardware prefetcher successfully predicts the access pattern. It automatically pulls the next sequential memory blocks into the L1 cache before the instructions execute.</p><p>By transitioning to this Structure of Arrays (SoA) layout, we eliminate the RAM bottleneck and let the CPU do what it does best. Raw, uninterrupted math.</p><h3>Wrapping Up</h3><p>DOD is ultimately about respecting the hardware. By packing our data into linear arrays, we eliminate severe memory bottlenecks and let the CPU do its job.</p><p>But this is just the beginning. Next time, we will continue our journey by exploring how to build simple, complete games using these exact Data-Oriented Design principles. Stay tuned, and thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72315fc22d95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Object Pooling: The Factory Pattern & Type Abstraction]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/advanced-object-pooling-the-factory-pattern-type-abstraction-058dd6d4f0e6?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/058dd6d4f0e6</guid>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Thu, 21 May 2026 12:49:37 GMT</pubDate>
            <atom:updated>2026-06-29T19:34:19.247Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous article on <a href="https://medium.com/@abdullahabdelati_46671/generic-object-pooling-67a574bb0580">Generic Object Pooling</a>, we explored how the standard Object Pooling pattern manages memory effectively by reducing garbage collection spikes. However, creating a dedicated pool manager script for every object type scales poorly in large projects.</p><p>Today, we will build an abstracted pooling system using the Factory pattern and Type caching to manage all prefabs through a single centralized manager.</p><p><strong>1. The Factory Pattern</strong> Object creation logic must be separated from memory management. A Factory handles instantiation, allowing the pool to request new objects without needing direct references to prefabs or specific instantiation methods.</p><pre>using UnityEngine;<br><br>public interface IFactory&lt;T&gt; where T : Component<br>{<br>    T Create();<br>}<br><br>public class PrefabFactory&lt;T&gt; : IFactory&lt;T&gt; where T : Component<br>{<br>    private readonly T _prefab;<br><br>    public PrefabFactory(T prefab)<br>    {<br>        _prefab = prefab;<br>    }<br><br>    public T Create()<br>    {<br>        return Object.Instantiate(_prefab);<br>    }<br>}</pre><p><strong>2. The Centralized Pool Manager<br></strong>Instead of isolated pool variables, we use a static Dictionary. This maps a class Type to its specific ObjectPool. The PoolManager provides a unified API for the entire application, caching multiple classes on demand.</p><pre>using System;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using UnityEngine.Pool;<br><br>public static class PoolManager<br>{<br>    private static readonly Dictionary&lt;Type, object&gt; _pools = new Dictionary&lt;Type, object&gt;();<br><br>    public static void InitializePool&lt;T&gt;(IFactory&lt;T&gt; factory, int defaultCapacity, int maxSize) where T : Component<br>    {<br>        if (_pools.ContainsKey(typeof(T))) return;<br><br>        var pool = new ObjectPool&lt;T&gt;(<br>            createFunc: factory.Create,<br>            actionOnGet: obj =&gt; obj.gameObject.SetActive(true),<br>            actionOnRelease: obj =&gt; obj.gameObject.SetActive(false),<br>            actionOnDestroy: UnityEngine.Object.Destroy,<br>            collectionCheck: true,<br>            defaultCapacity: defaultCapacity,<br>            maxSize: maxSize<br>        );<br><br>        _pools[typeof(T)] = pool;<br>    }<br><br>    public static T Get&lt;T&gt;() where T : Component<br>    {<br>        return ((ObjectPool&lt;T&gt;)_pools[typeof(T)]).Get();<br>    }<br><br>    public static void Release&lt;T&gt;(T obj) where T : Component<br>    {<br>        ((ObjectPool&lt;T&gt;)_pools[typeof(T)]).Release(obj);<br>    }<br>}</pre><h4>3. Implementation and Setup</h4><p>Initialize the pools during application startup or level load via a central script. Gameplay classes interact strictly with the static manager, requiring no knowledge of the underlying factory or prefab data.</p><pre>public class GameManager : MonoBehaviour<br>{<br>    [SerializeField] private Bullet _bulletPrefab;<br><br>    private void Start()<br>    {<br>        var bulletFactory = new PrefabFactory&lt;Bullet&gt;(_bulletPrefab);<br>        PoolManager.InitializePool(bulletFactory, defaultCapacity: 100, maxSize: 500);<br>    }<br>}</pre><h4>4. Usage in Gameplay Code</h4><pre><br>using UnityEngine;<br><br>public class Weapon : MonoBehaviour<br>{<br>    private void Update()<br>    {<br>        if (Input.GetButtonDown(&quot;Fire1&quot;))<br>        {<br>            Shoot();<br>        }<br>    }<br><br>    public void Shoot()<br>    {<br>        Bullet newBullet = PoolManager.Get&lt;Bullet&gt;();<br>        <br>        Vector3 safeSpawnPosition = transform.position + transform.forward;<br>        newBullet.transform.position = safeSpawnPosition;<br>        newBullet.transform.rotation = transform.rotation;<br><br>        Rigidbody rb = newBullet.GetComponent&lt;Rigidbody&gt;();<br>        if (rb != null)<br>        {<br>            rb.linearVelocity = Vector3.zero;<br>            rb.angularVelocity = Vector3.zero; <br>            rb.AddForce(transform.forward * 20, ForceMode.Impulse);<br>        }<br>    }<br>}</pre><pre>private void OnCollisionEnter(Collision collision)<br>{<br>    if (gameObject.activeSelf) <br>    {<br>        PoolManager.Release(this);<br>    }<br>}</pre><p><strong>Scaling to Other Types</strong><br>Because our manager uses Type abstraction, caching a completely different object requires zero new pooling logic. For example, spawning and returning an Enemy works exactly the same way:</p><pre>public class EnemySpawner : MonoBehaviour<br>{<br>    public void SpawnEnemy()<br>    {<br>        Enemy newEnemy = PoolManager.Get&lt;Enemy&gt;();<br>    }<br>}</pre><pre>public class Enemy : MonoBehaviour<br>{<br>    public void Die()<br>    {<br>        PoolManager.Release(this);<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*OZabLyBY52a1_vWxXWNEgw.gif" /></figure><h4>Wrapping Up</h4><p>Combining UnityEngine.Pool with a Factory pattern and a Type dictionary creates a highly scalable architecture. It enforces clean abstraction by decoupling gameplay logic from instantiation data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=058dd6d4f0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generic Object Pooling]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/generic-object-pooling-67a574bb0580?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/67a574bb0580</guid>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Sun, 17 May 2026 11:11:38 GMT</pubDate>
            <atom:updated>2026-07-31T07:33:49.910Z</atom:updated>
            <content:encoded><![CDATA[<p>The Object Pooling pattern is a great way to manage memory and reduce garbage collection spikes.</p><p>Today, we will build a generic object pooling system and use it inside a shooting system example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*V5NhnY6kJuHwGrKiowhDVQ.gif" /></figure><p>But before starting we should know Why are new and Destroy so bad for performance?</p><p>Frequently creating (Instantiate) and destroying objects like rapid fire bullets causes two major problems for your game&#39;s performance:</p><ol><li><strong>Creation is Heavy:</strong> Every time you create a new object, the CPU has to search for free memory and initialize the object. Doing this dozens of times per frame will quickly lower your framerate.</li><li><strong>Destruction Causes Lag Spikes:</strong> When you Destroy an object in C#, the memory isn&#39;t freed instantly; it becomes <strong>garbage</strong>. Eventually, the Garbage Collector (GC) has to completely pause your game to clean up this mess. This sudden pause is exactly what causes those annoying frame drops or stutters during heavy gameplay.</li></ol><p>That is where the <strong>Object Pooling</strong> pattern comes in. It simply involves deactivating the object when you are done with it, putting it in a <strong>pool</strong>, and reactivating it the next time you need one.</p><h3>Implementing UnityEngine.Pool</h3><p>Since Unity 2021, we don’t need to write a pooling manager from scratch. Unity provides a highly optimized, generic system built right into the UnityEngine.Pool namespace. It enforces clean architecture by requiring us to define exactly what happens when an object is created, requested, returned, and destroyed.</p><p>Let’s implement this with two scripts: a Weapon that manages the pool, and a Bullet that knows how to release itself.</p><p><strong>1. The Bullet just needs a return address.</strong> We use the SetPool() method to pass it a reference to the pool it was born in. When it hits a wall (or its lifetime expires), it simply calls _pool.Release(this). This is the exact equivalent of calling Destroy(), but instead of trashing the memory, it neatly returns itself to the pool manager.</p><pre>using UnityEngine;<br>using UnityEngine.Pool; <br><br>public class Bullet : MonoBehaviour<br>{<br>    private IObjectPool&lt;Bullet&gt; _pool;<br><br>    private float _lifeTime = 2f;<br><br>    public void SetPool(IObjectPool&lt;Bullet&gt; pool)<br>    {<br>        _pool = pool;<br>    }<br><br>    private void OnEnable()<br>    {<br>        Invoke(nameof(ReturnToPool), _lifeTime);<br>    }<br><br>    private void OnDisable()<br>    {<br>        CancelInvoke();<br>    }<br><br>    private void ReturnToPool()<br>    {<br>        _pool.Release(this);<br>    }<br><br>    private void OnCollisionEnter(Collision collision)<br>    {<br>        ReturnToPool();<br>    }<br>}</pre><p><strong>2. The Weapon makes the rules.</strong> The magic happens inside the Weapon&#39;s Awake() method. When we create the new ObjectPool&lt;Bullet&gt;, we have to define four rules:</p><ul><li><strong>Create:</strong> How to build a brand new bullet if the pool is empty.</li><li><strong>Take:</strong> What to do when a bullet is requested (turn it on with SetActive(true)).</li><li><strong>Return:</strong> What to do when a bullet comes back (turn it off with SetActive(false)).</li><li><strong>Destroy:</strong> What to do if the pool gets too full and we actually do need to delete one.</li></ul><pre>using UnityEngine;<br>using UnityEngine.Pool;<br><br>public class Weapon : MonoBehaviour<br>{<br>    [SerializeField] private Bullet bulletPrefab;<br>    [SerializeField] private float shootForce = 20f;<br><br>    [SerializeField] private float spawnOffset = 1.0f;<br><br>    [SerializeField] private bool collectionCheck = true;<br>    [SerializeField] private int defaultCapacity = 20;<br>    [SerializeField] private int maxSize = 100;<br><br>    private IObjectPool&lt;Bullet&gt; _bulletPool;<br><br>    private void Awake()<br>    {<br>        _bulletPool = new ObjectPool&lt;Bullet&gt;(<br>            CreateBullet, OnTakeBulletFromPool, OnReturnBulletToPool, OnDestroyBullet,<br>            collectionCheck, defaultCapacity, maxSize);<br>    }<br><br>    private void Update()<br>    {<br>        if (Input.GetButtonDown(&quot;Fire1&quot;))<br>        {<br>            Shoot();<br>        }<br>    }<br><br>    private void Shoot()<br>    {<br>        Bullet newBullet = _bulletPool.Get();<br><br>        Vector3 safeSpawnPosition = transform.position + (transform.forward * spawnOffset);<br><br>        newBullet.transform.position = safeSpawnPosition;<br>        newBullet.transform.rotation = transform.rotation;<br><br>        Rigidbody rb = newBullet.GetComponent&lt;Rigidbody&gt;();<br>        if (rb != null)<br>        {<br>            rb.linearVelocity = Vector3.zero;<br>            rb.AddForce(transform.forward * shootForce, ForceMode.Impulse);<br>        }<br>    }<br><br>    //The 4 Core Pooling Functions <br><br>    private Bullet CreateBullet()<br>    {<br>        Bullet bulletInstance = Instantiate(bulletPrefab);<br>        bulletInstance.SetPool(_bulletPool); <br>        return bulletInstance;<br>    }<br><br>    private void OnTakeBulletFromPool(Bullet bullet)<br>    {<br>        bullet.gameObject.SetActive(true);<br>    }<br><br>    private void OnReturnBulletToPool(Bullet bullet)<br>    {<br>        bullet.gameObject.SetActive(false);<br>    }<br><br>    private void OnDestroyBullet(Bullet bullet)<br>    {<br>        Destroy(bullet.gameObject);<br>    }<br>}</pre><p>Once those rules are set, shooting becomes as simple as calling _bulletPool.Get(). The pool automatically handles the rest!</p><h3>Wrapping Up</h3><p>Object pooling is a must-have pattern for high performance game development. By taking advantage of the built-in UnityEngine.Pool namespace, you save yourself from writing custom managers from scratch while protecting your game from those dreaded garbage collection lag spikes.</p><p>While we only built a shooting system today, the beauty of this being a <strong>generic</strong> pool is that you can apply this exact same code to anything: spawning enemies, popping up damage numbers, or handling complex UI elements.</p><p><strong>What system are you going to optimize with Object Pooling next? Let me know in the comments below, and if this guide helped you, feel free to leave a clap. Thanks for reading</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67a574bb0580" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sprite Atlas in Unity]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/sprite-atlas-in-unity-243a5c5a7e23?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/243a5c5a7e23</guid>
            <category><![CDATA[sprite-atlas]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Sun, 26 Apr 2026 17:42:10 GMT</pubDate>
            <atom:updated>2026-06-29T19:54:46.307Z</atom:updated>
            <content:encoded><![CDATA[<p>Sprite Atlas is a texture that combines multiple sprites into one large texture, reducing draw calls and memory usage.</p><p>By batching these images together, Unity can render them using a single draw call instead of processing each image individually. This efficiency is crucial for maintaining high frame rates and optimizing overall game performance, especially on mobile or performance constrained platforms.</p><p><strong>Set up Sprite Atlas:</strong></p><ul><li><strong>Create the Atlas:</strong> In your Project window, right-click and select Create &gt; 2D &gt; Sprite Atlas.</li><li><strong>Assign Sprites:</strong> Select the new Sprite Atlas. In the Inspector, find the <strong>Objects for Packing</strong> list and click the + button to add individual sprites or folders.</li><li><strong>Generate:</strong> Click the <strong>Pack Preview</strong> button at the bottom of the Inspector to build the combined texture.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/0*rgJS001CtVQvAP2L.png" /></figure><p><strong>Common Mistakes &amp; How to Fix Them</strong></p><p><strong>1. Poor Sprite Grouping</strong></p><ul><li><strong>The Mistake:</strong> Packing every sprite in the game (e.g., all enemies) into a single atlas.</li><li><strong>The Solution:</strong> Group sprites contextually, such as by specific levels, UI screens, or asset frequency.</li><li><strong>Why it’s essential:</strong> Loading Level 1 should not force the device to load textures for Level 5. Contextual packing ensures only necessary textures consume memory at any given time.</li></ul><p><strong>2. Using “Full Rect” Mesh Type</strong></p><ul><li><strong>The Mistake:</strong> Leaving the Sprite Import setting on “Full Rect” for irregular shapes.</li><li><strong>The Solution:</strong> Change the Mesh Type to Tight in the Sprite Import settings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/0*1qw4bxaqt2CE1AYi" /></figure><ul><li><strong>Why it’s essential:</strong> Full Rect forces the GPU to render large areas of transparent pixels, causing overdraw and wasting physical space on the atlas page. Tight crops out empty space, optimizing both rendering performance and atlas density.</li></ul><p><strong>3. Leaving Read/Write Enabled</strong></p><ul><li><strong>The Mistake:</strong> Keeping Read/Write Enabled checked on source sprites when not actively modifying their pixels via C# scripts.</li><li><strong>The Solution:</strong> Uncheck Read/Write Enabled on all sprites assigned to the atlas.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*WRz4YX_9T9sIssDo.png" /></figure><ul><li><strong>Why it’s essential:</strong> Enabling this forces Unity to keep a copy of the texture in both CPU and GPU memory simultaneously, instantly doubling its memory footprint for no benefit.</li></ul><h4><strong>Conclusion</strong></h4><p>Sprite Atlases are essential for optimizing performance, but watch out for a few other common pitfalls:</p><ul><li><strong>Double Compression:</strong> Set individual sprite compression to None so only the final atlas compresses, avoiding visual artifacts.</li><li><strong>Multi-page Atlases:</strong> If your atlas spills into multiple pages, it creates separate textures and ruins draw call optimization.</li><li><strong>Mismatched Secondary Textures:</strong> Don’t pack sprites that have normal maps with those that don’t, as it wastes space in the generated secondary texture.</li></ul><p>By avoiding these mistakes and structuring your atlases carefully, you ensure your game runs as smoothly as possible. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=243a5c5a7e23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LitMotion in Unity]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/litmotion-in-unity-79ee3f3c8d49?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/79ee3f3c8d49</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[motion-design]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Thu, 09 Apr 2026 13:05:18 GMT</pubDate>
            <atom:updated>2026-04-26T17:52:09.975Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/annulusgames/LitMotion"><strong>LitMotion </strong></a>is a modern, ultra-fast tweening library for Unity. It features <strong>zero memory allocation</strong> (no Garbage Collection spikes) and its use of <strong>Unity’s DOTS (Job System + Burst Compiler)</strong> under the hood for massive performance gains over older libraries like DOTween.</p><p>It also has built-in, modern support for async/await (via UniTask) and reactive programming (UniRx/R3).</p><p>Today, we’ll build emoji animations using LitMotion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*gAe2XvnctKhh_T_DZPbysw.gif" /></figure><p>Install LitMotion via the Unity Package Manager by selecting <strong>Add package from git URL…</strong> and pasting this link: <a href="https://github.com/annulusgames/LitMotion.git?path=src/LitMotion/Assets/LitMotion">https://github.com/annulusgames/LitMotion.git?path=src/LitMotion/Assets/LitMotion</a></p><h3>The 4 Pillars of LitMotion</h3><p>Before we dive into building the complex Sad Emoji animation, let’s quickly break down the four core tools we’ll be using to make it happen.</p><p><strong>1.</strong><strong>LMotion.Create()</strong> Every animation starts here. You are simply telling LitMotion three things: Where do I start?<em> </em>Where do I end? How long should it take? <em>(Example: </em><em>LMotion.Create(0, 10, 2f) goes from 0 to 10 over 2 seconds).</em></p><p><strong>2.</strong><strong>BindTo...</strong> LMotion.Create only generates numbers. To actually move an object in Unity, we need to apply those numbers to a component. Methods like .BindToLocalScale() or .BindToLocalEulerAngles() act as the glue, directly pumping those changing numbers into your Transform.</p><p><strong>3.</strong><strong>LoopType.Yoyo</strong> By default, if you loop an animation, it snaps back to the beginning when it finishes. LoopType.Yoyo tells the animation to play forward, then smoothly play in reverse. It is perfect for creating natural, breathing, or rocking motions.</p><p><strong>4.</strong><strong>async &amp; </strong><strong>.ToUniTask()</strong> Normally, code executes instantly. If we wrote three animation commands in a row, they would all try to play at the exact same time. By adding async to our method and .ToUniTask() to the end of our animation, we create a traffic light. We can tell the code to await (pause) until the first animation completely finishes before starting the next one. This allows us to perfectly sequence complex movements!</p><h4>Wow Emoji</h4><p>This animation combines a smooth scale pulse with a gentle rocking motion on the X-axis to simulate breathing and awe.</p><pre>[SerializeField] private Transform wowEmoji;<br>[SerializeField] private float wowEmojiScaleDuration = 0.5f;<br>[SerializeField] private float wowEmojiRotateDuration = 1;<br><br>private void AnimateWowEmoji()<br>{<br>    LMotion.Create(wowEmoji.localScale, wowEmoji.localScale * 1.2f, wowEmojiScaleDuration)<br>        .WithEase(Ease.InOutSine)   <br>        .WithLoops(-1, LoopType.Yoyo)<br>        .BindToLocalScale(wowEmoji);<br><br>    LMotion.Create(new Vector3(-60, 0, 0), new Vector3(-120, 0, 0), wowEmojiRotateDuration)<br>        .WithEase(Ease.Linear)<br>        .WithLoops(-1, LoopType.Yoyo)<br>        .BindToEulerAngles(wowEmoji);<br>}</pre><h4>Sad Emoji</h4><p>The sad emoji needs a more complex, sequential animation. It looks down heavily, tilts to the side, and then shakes its head endlessly. We use async/await to chain these movements together perfectly.</p><pre> [SerializeField] private Transform sadEmoji;<br> [SerializeField] private float sadEmojiScaleDuration = 0.5f;<br> [SerializeField] private float sadEmojiRotateDuration = 1;  <br><br> private async void AnimateSadEmoji()<br>    {<br>        await LMotion.Create(new Vector3(-90, 0, 0), new Vector3(-50, 0, 0), sadEmojiRotateDuration)<br>            .WithEase(Ease.Linear)<br>            .BindToLocalEulerAngles(sadEmoji)<br>            .ToUniTask();<br><br>        await LMotion.Create(new Vector3(-50, 0, 0), new Vector3(-50, 0, 50), sadEmojiRotateDuration / 2f)<br>            .WithEase(Ease.Linear)<br>            .BindToLocalEulerAngles(sadEmoji)<br>            .ToUniTask();<br>        <br>        LMotion.Create(new Vector3(-50, 0, 50), new Vector3(-50, 0, -50), sadEmojiRotateDuration)<br>            .WithEase(Ease.Linear)<br>            .WithLoops(-1, LoopType.Yoyo)<br>            .BindToLocalEulerAngles(sadEmoji);<br>    }</pre><h4>Love Emoji</h4><p>For a love reaction, a bouncy heartbeat effect is the standard. We use Ease.OutBack to create a snappy pop that slightly overshoots its target size before settling.</p><pre> [SerializeField] private Transform loveEmoji;<br> [SerializeField] private float loveEmojiScaleDuration = 0.5f;<br> [SerializeField] private float loveEmojiScaleFactor = 1.3f;<br><br>    private void AnimateLoveEmoji()<br>    {<br>        LMotion.Create(loveEmoji.localScale, loveEmoji.localScale * loveEmojiScaleFactor, loveEmojiScaleDuration)<br>            .WithEase(Ease.OutBack)   <br>            .WithLoops(-1, LoopType.Yoyo)<br>            .BindToLocalScale(loveEmoji);<br>    }</pre><h3>Wrapping Up</h3><p>LitMotion completely changes how we handle UI and transform animations in Unity. By combining zero-allocation performance with modern features like async/await, you can build complex, chained animations without sacrificing your frame rate or dealing with messy coroutines.</p><p>Swap out your old tweening libraries and give LitMotion a try on your next project. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79ee3f3c8d49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ScriptableObjects as an Event Bus]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/scriptableobjects-as-an-event-bus-23e02a880df7?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/23e02a880df7</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[scriptabelobject]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Sun, 05 Apr 2026 16:05:01 GMT</pubDate>
            <atom:updated>2026-06-29T20:35:17.486Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, we’re going to explore how to achieve <strong>decoupling </strong>between classes using ScriptableObjects.</p><p>ScriptableObjects are incredibly useful and are widely used for various purposes, such as acting as an <strong>event bus, storing shared data, reducing memory usage,</strong> <strong>managing inventory systems, and creating pluggable AI behaviors.</strong></p><p>To demonstrate this, we’ll tackle a very common challenge: notifying the UI to update the coin count when the player picks up a coin, without the player script and the UI script needing to know about each other.</p><p><strong>First</strong>, create a new C# script called IntEventChannelSO. In this script, we need a C# Action to handle the event, and a public method to raise it, as shown below:</p><pre>using System;<br>using UnityEngine;<br><br>[CreateAssetMenu(menuName = &quot;Events/IntEventChannel&quot;)]<br>public class IntEventChannelSO : ScriptableObject<br>{<br>    public Action&lt;int&gt; OnEventRaised;<br><br>    public void RaiseEvent(int value)<br>    {<br>        OnEventRaised?.Invoke(value);<br>    }<br>}</pre><p>Now, let’s back into the Unity Editor. Right-click in your Project window, navigate to <strong>Create &gt; Events &gt; IntEventChannel</strong>, and name the new file CoinChannel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQkHWH7e8zBnZtgqBpWscg.png" /></figure><p>We need our Player to trigger the event. When the player collides with a coin, it will raise the event, notifying any active listeners — like our CoinsUI script—to update the text.</p><pre>using UnityEngine;<br><br>public class Player : MonoBehaviour<br>{<br>    [SerializeField] private IntEventChannelSO coinChannel;<br>    <br>    private void OnTriggerEnter(Collider other)<br>    {<br>        if (other.CompareTag(&quot;Coin&quot;))<br>        {<br>            coinChannel?.RaiseEvent(1);<br>            other.gameObject.SetActive(false);<br>        }<br>    }<br>}</pre><pre>using TMPro;<br>using UnityEngine;<br><br>public class CoinsUI : MonoBehaviour<br>{<br>    [SerializeField] private TextMeshProUGUI coinText;<br>    [SerializeField] private IntEventChannelSO coinChannel;<br><br>    private int currentCoins = 0;<br><br>    private void OnEnable()<br>    {<br>        coinChannel.OnEventRaised += UpdateCoinDisplay;<br>    }<br><br>    private void OnDisable()<br>    {<br>        coinChannel.OnEventRaised -= UpdateCoinDisplay;<br>    }<br><br>    private void UpdateCoinDisplay(int amountToAdd)<br>    {<br>        currentCoins += amountToAdd;<br>        coinText.text = currentCoins.ToString();<br>    }<br>}</pre><p>And here we are with the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rj-lqDXixVo7OvPlTC0rEw.gif" /></figure><h4><strong>Conclusion</strong></h4><p>Using ScriptableObjects as an Event Bus is a powerful way to keep our Unity projects clean. By decoupling our Player from the UI, we avoid messy dependencies and make our game much easier to manage as it grows.</p><p>See you in the next post for another useful ScriptableObject topic. Thanks for reading!</p><p>If you want to see what else I’m working on, connect with me on <a href="https://www.linkedin.com/in/abdullah-abdelati/"><strong>LinkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23e02a880df7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Remote Addressables in Unity]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/addressables-in-unity-part-2-5d9488f1421f?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d9488f1421f</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-addressable]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Thu, 26 Mar 2026 11:17:17 GMT</pubDate>
            <atom:updated>2026-08-21T09:07:59.881Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous post, we talked about <strong>local</strong> Addressables and how to set them up (you can check that out <a href="https://medium.com/@abdullahabdelati_46671/addressables-in-unity-4cfb871c2222"><strong>here</strong></a>)</p><p>Today, we will move on to <strong>remote</strong> Addressables using <strong>Unity Cloud Content Delivery (CCD)</strong>. This means we will upload our game assets to the Unity Cloud and retrieve them through our code exactly when we need them.</p><p>Here is what we will build today: A <strong>3-story</strong> building where each floor has its own prefabs. We will upload these floors (prefabs) to the Unity Cloud. When the player presses a floor number, we will trigger the download. This means while the player is riding <strong>the</strong> <strong>elevator</strong>, we are secretly downloading and loading the exact assets we need so they are ready before the doors even open!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPSWvFknN5RJicLXgh1GSQ.gif" /></figure><h4>Setting up remote Addressables:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*_VT9VRUPH4yCmBumAq9htw.png" /></figure><p><strong>1. Enable the Remote Catalog:</strong></p><ul><li>Click on the <strong>AddressableAssetSettings</strong> file (the one selected in the above image ☝️).</li><li>In the Inspector window, scroll down to the <strong>Catalog </strong>section and check the box for <strong>Build Remote Catalog.</strong></li><li>Click the <strong>Build &amp; Load Paths</strong> dropdown (which currently says &lt;custom&gt;) and change it to <strong>Remote</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*U4ARBop7Tq5oYLslSIFR3A.png" /></figure><p><strong>2. Configure Profile Paths:</strong></p><p>1. Go to the top Unity menu and click Window &gt; Asset Management &gt; Addressables &gt; Profiles.</p><p>2. Look for the Remote section. You will see two important paths:</p><p>—<strong> Remote.BuildPath:</strong> Leave this as the default (usually ServerData/[BuildTarget]). This tells Unity where to put the files on your computer when it builds them.</p><p>—<strong> Remote.LoadPath:</strong> This is where your game will look for the files on the internet. We will paste the Unity Cloud (CCD) link here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*WqXqPpUBupQBj5Yju-ClBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*nrEfmqNjXRhgM92O1UFHLg.png" /></figure><p><strong>3. Set Your Asset Groups to Remote</strong></p><ol><li>Open the Addressables Groups window (Window &gt; Asset Management &gt; Addressables &gt; Groups).</li><li>Select the specific group that contains your 3-floor prefabs.</li><li>Look at the Inspector window and find the Content Packing &amp; Loading section.</li><li>Change the Build Path dropdown to <strong>&lt;Remote.BuildPath&gt;</strong>.</li><li>Change the Load Path dropdown to <strong>&lt;Remote.LoadPath&gt;</strong>.</li></ol><p><strong>6. Separate Your Downloads (Crucial Step)</strong></p><p>— By default, Unity packs all files in a group into one giant download. If a player goes to Floor 1, they would be forced to download Floor 2 and 3 at the same time!</p><ol><li>To fix this so they only download what they need:</li></ol><ul><li>Still in the Inspector for your group, expand the <strong>Advanced Options</strong> section.</li><li>Find <strong>Bundle Mode</strong> and change it from Pack Together to <strong>Pack Separately</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FB5CySoa9HscTUe2226bHA.png" /></figure><blockquote><em>Note: When you build your Addressables later, Unity will put these separate files inside a new yellow folder (remotefloors_assets_assets). When uploading to the Unity Cloud dashboard, make sure to drag and drop that </em><strong><em>entire folder</em></strong><em> into the browser, not just the files inside it!</em></blockquote><p>Just upload all that in the image below to the cloud</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*gKvZtEmus9DKCCQ4Denziw.png" /></figure><p><strong>4. Unity Cloud Content Delivery (CCD) Setup:</strong></p><p>1. Open the Unity Cloud Dashboard</p><p>— Go to the Unity Cloud Dashboard in your web browser and sign in.</p><p>— Select your current project from the list.</p><p>2. Navigate to CCD</p><p>— On the left-hand menu, find and click on Cloud Content Delivery.</p><p>3. Create a Bucket</p><blockquote>Bucket is just a folder in the cloud where the game assets will live.</blockquote><p>— Click Create Bucket.</p><p>— Name it something clear, like RemoteFloorsBucket, and create it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijp5W-BZTai-egSImW9-Gw.png" /></figure><h4>Finally, upload the files into that new bucket:</h4><p><strong>1. Build the Addressables</strong></p><p>— Open the Addressables Groups window.</p><p>— Click Build &gt; New Build &gt; Default Build Script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yjaA3F-3U_f0EnLbmVs8w.png" /></figure><p>— Unity will create your remote files inside a folder called ServerData in your main project directory.</p><p><strong>2. Upload to Unity Cloud</strong></p><p>— Go back to your bucket on the Unity Cloud Dashboard.</p><p>— Click the Upload button.</p><p>— Drag and drop the files from your <strong>ServerData</strong> folder (usually inside a folder named StandaloneWindows64 or Android) right into the browser.</p><p>3. Create a Release</p><p>— Once uploaded, click Create Release in the dashboard. This officially publishes your 3-floor prefabs files to the cloud!</p><p>— <strong>Back </strong>to Unity, open the Addressables <strong>Profiles</strong> window, and paste that link directly into the <strong>Remote.LoadPath</strong> box we looked at earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eV6ZhbsHWVDyLsd6hWVNJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*K7RAQfrAwO8yntd9lRHxXg.png" /></figure><p>Now let’s fetch those floors while riding the elevator.</p><pre>using UnityEngine;<br>using UnityEngine.AddressableAssets;<br>using UnityEngine.ResourceManagement.AsyncOperations;<br><br>public class AddressbleManager : MonoBehaviour<br>{<br>    [SerializeField] private IntEventChannelSO onFloorSelected;<br>    <br>    [SerializeField] private AssetReference[] floorReferences;<br>    <br>    private AsyncOperationHandle&lt;GameObject&gt; _currentFloorReceipt;<br><br>    private void OnEnable()<br>    {<br>        onFloorSelected.OnEventRaised += LoadFloor; <br>    }<br><br>    private void OnDisable()<br>    {<br>        onFloorSelected.OnEventRaised -= LoadFloor;<br>    }<br><br>    private void LoadFloor(int floorIndex)<br>    {<br>        if (floorIndex &lt; 0 || floorIndex &gt;= floorReferences.Length) return;<br>        <br>        if (_currentFloorReceipt.IsValid())<br>        {<br>            Addressables.ReleaseInstance(_currentFloorReceipt);<br>        }<br>        _currentFloorReceipt = floorReferences[floorIndex].InstantiateAsync();<br>    }<br>}</pre><p>When the player presses (1), the ElevatorController script raises our integer event. The AddressableManager listens for this number and immediately starts downloading <strong>floor_1</strong>.</p><p>The real magic happens when moving between floors. If we are currently on <strong>the third floor</strong> and the player presses the button to go down to <strong>the first floor</strong>, the script will completely release <strong>floor_3</strong> from memory before it starts loading <strong>floor_1</strong>. This keeps our RAM usage perfectly clean!</p><blockquote><strong>Hint:</strong> Once the assets are downloaded for the first time, Unity automatically caches them locally. The next time the player visits those floors, they will load almost instantly from the device’s hard drive instead of downloading from the internet!</blockquote><h3>Testing the Results:</h3><p>To truly understand why that Pack Separately setting is so important, let’s look at what happens in the Unity Console when we ask the server to download our floors.</p><p><strong>Scenario A: “Pack Together” (The Default)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*ncgy3Ro7vUAXm1WqvOlp5w.png" /></figure><p>If we leave the group set to the default <strong>Pack Together</strong>, requesting the first floor forces the game to download a larger file containing all three floors at once. Then if we move to Floor 2 or 3, notice how Floor 2 and Floor 3 say <strong>“already cached”</strong>? That is because they were secretly downloaded alongside <strong>Floor 1</strong>. This is fine for tiny prefabs, but it would be a nightmare if each floor was a massive 500 MB 3D environment!</p><p><strong>Scenario B: “Pack Separately” (Optimized)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*3OLh03f26NisT3C_VagXZQ.png" /></figure><p>After changing the setting to <strong>Pack Separately</strong> and uploading our new folder to the Unity Cloud, look at the difference! Pressing <strong>Floor 1</strong> only downloads the exact bytes needed for that specific floor. When the player eventually goes to Floor 2, it triggers a brand-new, separate download and so on.</p><p>We have successfully optimized our network usage so the player only downloads exactly what they need, exactly when they need it.</p><blockquote><strong>Note:</strong> If you are testing this inside the Unity Editor, make sure to change your <strong>Play Mode Script</strong> to <strong>Use Existing Build</strong>! By default, the Editor uses “Asset Database (fastest)”, which skips the internet and instantly loads your local project files (the floors prefabs). Switching to “Existing Build” forces the Editor to act like a real player’s phone and actually download the files from your Unity Cloud bucket.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*x1ib-kZqEHgpKNlJhIrs1g.png" /></figure><h3>Wrapping Up</h3><p>And that’s it! We have successfully moved our 3D assets to the cloud.</p><p>By combining Unity Addressables with Cloud Content Delivery (CCD), we can download levels on the fly and release them from memory when they are no longer needed. This keeps our game’s initial download size small and our RAM usage highly optimized.</p><p>If you found this helpful, let me know in the comments, and don’t forget to check out <a href="https://medium.com/@abdullahabdelati_46671/addressables-in-unity-4cfb871c2222"><strong>Part 1</strong></a> if you missed it. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d9488f1421f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local Addressables in Unity]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/addressables-in-unity-4cfb871c2222?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cfb871c2222</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 09:53:19 GMT</pubDate>
            <atom:updated>2026-08-21T09:08:38.200Z</atom:updated>
            <content:encoded><![CDATA[<p>We use <strong>Addressables</strong> to manage memory, reduce initial app size, push live updates without app store approvals, and drastically speed up our build times.</p><h4>Memory Management: Addressables vs. Standard Unity</h4><p><strong>Before</strong> we start <strong>setting up</strong> Addressables, you might be asking yourself: what is the difference between Addressables (Load and Unload) and standard Unity methods (Instantiate and Destroy)? 🤔</p><p>The main difference is <strong>when</strong> the asset goes into your memory. With standard Unity, the <strong>Blueprint</strong> (your heavy prefab data) is forced into your main memory (RAM) the moment the scene starts, even before you use Instantiate.</p><p>Addressables, however, keep that Blueprint sitting safely on your hard drive. It will <strong>NOT </strong>load into memory until you explicitly tell it to through your code. This saves a massive amount of RAM and makes your game load much faster!</p><p>The same logic applies to cleaning up. Unity’s normal Destroy() method only deletes the lightweight &quot;<strong>Clone</strong>&quot; from your active scene, leaving the heavy Blueprint stuck in your RAM. Addressables&#39; Unload method completely frees your memory, removing the Blueprint from RAM and leaving it on the hard drive until you need to load it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*28gxJpnXUdPoPh03exnWXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*K0hFBlnPx-WmxfMJeLA5nQ.png" /></figure><h4>How to Set Up Addressables</h4><p><strong>Alright let’s setup the Addressables: </strong>First things first we need to install <strong>Addressables</strong> package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rgHjICCFNtwT6q3NwbJoQ.png" /></figure><p>To make any asset Addressable, just select it and check the ‘Addressable’ box in the Inspector, like in the image below 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xG0R08asM4FtjFAsrecKlA.png" /></figure><p>Now, for example, if we want to load the Player on start and delete it when we press a key, we can use this script:</p><pre>using UnityEngine;<br>using UnityEngine.AddressableAssets;<br>using UnityEngine.ResourceManagement.AsyncOperations; <br><br>public class AddressbleManager : MonoBehaviour<br>{<br>    [SerializeField] private AssetReference _player;<br>    <br>    private AsyncOperationHandle&lt;GameObject&gt; _playerReceipt;<br><br>    void Start()<br>    {<br>        _playerReceipt = _player.InstantiateAsync();<br>    }<br><br>    void Update()<br>    {<br>        if (Input.GetKeyDown(KeyCode.D) &amp;&amp; _playerReceipt.IsValid())<br>        {<br>            Addressables.ReleaseInstance(_playerReceipt);<br>        }<br>    }<br>}</pre><p>Think of AsyncOperationHandle as your &quot;receipt&quot; to manage asynchronous operations initiated through the Addressables API.</p><p>Now, if we start the game, the Player will spawn. When we press <strong>‘D’</strong>, the clone is destroyed and the blueprint is cleared from memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mR8CjvjjIIBJmuGykJxhxA.png" /></figure><h4><strong>Live Updates (Remote Content)</strong></h4><p>We can push new content, tweak levels, or fix broken textures by updating assets on a server. Players download the new assets directly when they open the game, completely bypassing the need for a new Google Play Store review and update.</p><blockquote><strong>Note:</strong> I will be diving much deeper into how to set up Remote Content in a future blog post, so stay tuned!</blockquote><h4><strong>Faster Build Times &amp; CI/CD</strong></h4><p>Because Addressables separate our assets from our code, we don’t have to rebuild the entire game every time we change a prefab. This makes daily iteration much faster and makes automating your builds through CI/CD pipelines much cleaner.</p><p>And that’s it for today’s blog post. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cfb871c2222" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assemblies in Unity]]></title>
            <link>https://medium.com/@abdullahabdelati_46671/assemblies-in-unity-e72aa246b6ab?source=rss-1006694e725e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e72aa246b6ab</guid>
            <dc:creator><![CDATA[Abdullah]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 10:13:19 GMT</pubDate>
            <atom:updated>2026-02-27T16:55:10.215Z</atom:updated>
            <content:encoded><![CDATA[<p>Assemblies are useful in many ways like (Faster Compilation, Better Dependency Management, Platform-Specific Compilation, etc…<strong>)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ysPgJViEskayjGwWw5iXA.jpeg" /></figure><p>We will check those in detail but first let’s add<strong> Assembly Definition Files </strong>by Right-click in Project window → Create → Assembly Definition.</p><p>For example, we have a project and has this Architecture.</p><p><strong>Assets folder:</strong></p><ul><li><strong>Core Folder</strong> (Core.asmdef): Zero dependencies. Every other folder depends on this one.</li><li><strong>Systems Folder</strong> (Systems.asmdef): Depends only on the Core folder.</li><li><strong>UI Folder</strong> (UI.asmdef): Sits on top. Depends on both Core and Systems.</li><li><strong>Tests Folder</strong> (Tests.asmdef): Test-only code. Never ships in your final build.</li><li><strong>iOS Folder (</strong>iOSFeatures.asmdef) : Set to: Include ONLY iOS platform</li><li><strong>Android Folder (</strong>AndroidFeatures.asmdef) : Set to: Include ONLY Android platform</li></ul><p>With doing that we actually achieve <strong>Faster Compilation</strong> because without <strong>Assembly Definition </strong>any changes you make in your scripts, Unity will recompile all scripts in the project, but now<strong> </strong>only the <strong>affected assembly</strong> and those that depend on it are recompiled.</p><h4>Enforced Decouple Code (No Spaghetti Code):</h4><ul><li>Scripts inside an assembly <strong>cannot</strong> access internal members of another assembly.</li><li>Enforces architectural boundaries — e.g., If UI assembly needs to talk to Player assembly, you have to explicitly define a dependency. This prevents you from writing tangled &quot;spaghetti code&quot; where everything references everything else, forcing you to write cleaner, more modular systems.</li></ul><p>e.g: Assume the GameEvents lives in the Core folder, <strong>both</strong> UI assembly and Player assembly need to manually add Core.asmdef to their <strong>&quot;Assembly Definition References&quot;</strong> list in the Inspector. Now if we have a script called <strong>FloatEventChannelSO</strong> lives in the Core folder(Core.asmdef)</p><pre>using System;<br>using UnityEngine;<br><br>[CreateAssetMenu(menuName = &quot;Events/FloatEventChannel&quot;)]<br>public class FloatEventChannelSO : ScriptableObject<br>{<br>    public Action&lt;float&gt; OnEventRaised;<br>    <br>    public void RaiseEvent(float value)<br>    {<br>        OnEventRaised?.Invoke(value);<br>    }<br>}</pre><p>Then give <strong>The Player (Shouter) </strong>script a public FloatEventChannelSO healthChannel; variable. Drag the SO asset into this slot. When damaged, call healthChannel.RaiseEvent(health);</p><p>And for <strong>The UI (Listener):</strong> Give your UI script the exact same public FloatEventChannelSO healthChannel; variable. Drag the same SO asset into this slot. Subscribe to healthChannel.OnEventRaised.</p><p>Now The Player doesn’t know about the UI and vice versa<strong> “Decoupling successfully achieved”.</strong></p><blockquote><strong><em>NOTE: </em></strong><em>This example using the ScriptableObject does the actual job of decoupling the code. You could use that in a </em><strong><em>normal </em></strong><em>project without </em><strong><em>assemblies,</em></strong><em> and it would work great.</em></blockquote><blockquote><em>Adding assemblies just acts like a security guard. It physically forces you to keep that clean architecture, so you or another developer doesn’t accidentally ruin it later, while also giving you all those other benefits like faster compile times.</em></blockquote><h4>Platform-Specific Compilation:</h4><ul><li>We can configure an assembly to <strong>only compile for specific platforms</strong> (e.g.: only for iOS, or exclude WebGL).</li><li>Cleaner than scattering #if UNITY_IOS preprocessor directives everywhere.</li></ul><p>The old way:</p><pre>void DoSomething()<br>{<br>#if UNITY_IOS<br>    iOSCamera.DoThing();<br>#endif<br><br>#if UNITY_ANDROID<br>    AndroidPlugin.DoThing();<br>#endif<br>}</pre><p>but the Better Way by using Assembly Platform Filter Like we did above:</p><ul><li><strong>iOS Folder (</strong>iOSFeatures.asmdef) : Set to: Include ONLY iOS platform</li><li><strong>Android Folder (</strong>AndroidFeatures.asmdef) : Set to: Include ONLY Android platform.</li></ul><p>This exactly like you tell Unity only compile this entire folder of scripts when building for iOS. Ignore it completely for everything else.</p><p>There are many useful things by using <strong>Assemblies in Unity,</strong> we will discuss that in the future blogs. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e72aa246b6ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>