Improving Game Architecture Practices

Aug 19, 2024

Signs of Problematic Game Architecture

Introduction

  • Presented by Jason.
  • Focus on identifying problems in game architecture and practical solutions to address them.
  • Aims to help complete and release projects more efficiently.

Common Issues in Game Architecture

1. Game Logic in UI

  • Problem: Mixing game state data with UI logic.
    • Starts with small state data (e.g., health, ammo) in the UI.
    • Leads to messy code as the project grows.
  • Recommendation:
    • Keep game state data out of UI.
    • Use data binding methods to update UI elements based on changes in the data source.
    • Implement a game state manager or a state machine to control game flow.

2. Monolithic Classes

  • Problem: Large classes (thousands of lines) cause brittleness and difficulty in maintenance.
    • Changes in one part can break other parts of the game.
  • Recommendation:
    • Regularly refactor code to keep classes manageable.
    • Split large classes into smaller, more focused classes.

3. Public Fields

  • Problem: Overusing public fields causes confusion between prefab data and runtime state data.
    • Can lead to spaghetti code and hard-to-follow dependencies.
  • Recommendation:
    • Use private fields by default.
    • Only expose fields that are necessary for other classes.

4. Setters with Side Effects

  • Problem: Setters performing additional actions can cause unexpected behavior and performance issues.
  • Recommendation:
    • Keep setters simple. Avoid hidden complexity.
    • Use distinct methods for setting values and handling side effects.

5. Giant Prefabs

  • Problem: Large prefabs are hard to manage and change, complicating collaboration.
  • Recommendation:
    • Break down large prefabs into smaller, manageable pieces.
    • Use nested prefabs or prefab variants for better organization.

6. Ignoring Interfaces

  • Problem: Not using interfaces can lead to complicated and messy code.
  • Recommendation:
    • Learn and implement interfaces to promote clean architecture and allow for code flexibility.
    • Use interfaces to handle shared functionality across different classes.

7. Garbage Collection and Performance Issues

  • Problem: Ignoring garbage collection leads to performance degradation.
  • Recommendation:
    • Investigate garbage allocations using the profiler.
    • Get into the habit of optimizing code for performance, especially as projects grow.

8. Lack of Sharing and Feedback

  • Problem: Not sharing code limits growth and learning opportunities.
  • Recommendation:
    • Share code with peers, get feedback, and learn from others' architectures.
    • Join communities (like Discord) to discuss and review code.

Conclusion

  • Importance of addressing these architecture issues for better project outcomes.
  • Encouragement to share the video and engage with the community for further learning.