Mechanics Analyses | Drone Interceptors | Log 2

Architecting a Drone Loadout System

Published: Jan 10th, 2023



Introduction

Our clients are looking for ways to customize their drones, so that they can easily add or remove components to fine-tune them before deploying them. They desire a playground in which to experiment with different drone configurations in order to test and evaluate the most effective strategies for intercepting drone swarms. To construct such a system it was crucial to gather information on existing approaches to loadout and customisation systems in published games and the techniques that were employed to build them.

Research

Drone Loadout Moodboard

The Decorator Pattern

The Decorator pattern is part of the structural design pattern family. It permits the addition of new functionalities to an object without altering the object iself. The Decorator wraps the original class making it easy to attach and detach new behaviours to an object.

The Decorator pattern is heavily dependant on using a class constructor. With native Unity API classes however (Monobehaviour, ScriptableObject) the engine takes care of initialising classes that are attached to GameObjects (in the case of MonoBehaviours). Initialisation code is expected to be used in Unity's Awake() and Start() callbacks. Therefore, to use the Decorator pattern while still taking advantage of the core Unity API features, it must be adapted.

Benefits and Drawbacks

  • Alternative to subclassing - Inheritance doesn't permit extending an object's behaviour at runtime
  • Runtime dynamics - Add or remove functionality at runtime, even returning an object to it's original form if necessary by removing its decorators
  • Relationship complexity - Can become complicated if there are multiple layers of decorators wrapped around an object making it difficult to keep track of the chain of initialisation
  • Code complexity - Can add complexity to the code base if several decorator classes need to be maintained

Decorator Use Cases

  • Collectible card game - Augmenting base card powers with artifact cards
  • Wardrobe system - Decorating player characters with armour and accessories to buff specific stats

Implementation