Benefits and drawbacks

It can be challenging to pinpoint the common drawbacks of the State pattern, because managing states are fundamental to game development, so we could say that this pattern is essential and cannot be disregarded. The following are the benefits of using the State pattern:

  • Encapsulated behaviors: The State pattern allows us to implement an entity's behaviors as a collection of self-contained components that can be attached dynamically to an object when it changes states.
  • Reduction of condition blocks: Using the State pattern reduces the need for huge chunks of if-else conditions or switching cases, because behaviors can be dynamically assigned depending on an object's internal or global state change.

There is only one ...

Get Hands-On Game Development Patterns with Unity 2019 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.