Optimizing Weapon Pickup Inheritance Using Structs
<p>I was brought onto a project with <strong><em>Zygobot Studios</em></strong> recently, and I want to share some optimization techniques that I implemented into the project, so I’m starting a new series with this article.</p>
<p>Let’s take a look at how I optimized the weapon pick up system in the game.</p>
<p>Originally when I came onto the project, it had quite the convoluted design when it came to weapon pick ups. They were some levels on inheritance, but a lot of code that could have been passed down from parent to child was repeated. For example, the code that called a user widget when a pick up was being overlapped by the player character was repeated in every item. This approach brazenly violated the <strong>DRY</strong> principle, so the first order of business was to fix that.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:770/1*807jP6PKxTIPl7NqQh3tCA.png" style="height:256px; width:700px" /></p>
<p>We want to make sure to re-use code as much as we can</p>
<p>I first made where there was a base <strong><em>BP_Item </em></strong>that contained all of the functionality it needed, including any applicable interfaces, and applied them to the base <strong><em>BP_Item</em></strong>.</p>
<p>Now, I could have just stopped there, have variables that are exposed on the <strong><em>BP_Item</em></strong>, have each child inherit them, and let the game designers have at it when it comes to placing items. Game over, it’s a wrap!</p>
<p><a href="https://medium.com/@christopherguyton87/optimizing-weapon-pickup-inheritance-using-structs-ee4c94ea1995"><strong>Website</strong></a></p>