Posts

Showing posts from January, 2023

Classcade : A Pattern for Modular Controllers in Unity

Modular code with well-defined singular responsibilities is A Good Thing, and far better minds than mine are a Google search away to tell you why. However, in some situations, avoiding a monolothic block of code or a spaghetti of dependencies is a challenge.  For me, player-character control logic (PCL) always presents an architectural headache, especially in an evolving project. PCL seems to demand an awkward tangle of states and layers that all have a finger or two in each other's pies, and edge-cases abound. Modularity can seem like wasted effort, as everything ends up so project-specific that little can be reused. Rather than continue to try to force it into ill-fitting 'good' code patterns, I decided to embrace the need for PCL code to be aware of other systems and refocus. My new goals were: A super lightweight framework to nudge me in the right direction at all times Genuine modularity with arm's-length interactions, substitution, inheritance, ideally via interfa...