Skip to main content

Collectables

Written by: Akram Taghavi-Burris | © Copyright 2024
Status

In many games, collectables play a vital role in enhancing player experience. These collectables can take various forms, such as coins, power-ups, or resources, but their primary purpose is often to provide the player with value, like earning points or enhancing stats. While the types of collectables might vary, their core properties tend to remain consistent across similar items.

Given that games can feature a large number of collectables with similar attributes, using Scriptable Objects to store their data is an efficient solution. Scriptable Objects allow us to manage shared properties for collectables (e.g., value, rarity, type) in a centralized way, reducing memory usage and promoting reusability.

Additionally, the behavior of collectables is often simple and consistent across different objects. For this reason, we can implement a streamlined Collectable component that focuses primarily on what happens when the object is collected.

System Architecture for Collectables

The Collectables system will comprise several key components, including a base collectable class, a collector, and a collection manager. Like the Movables system, the goal is to ensure reusability, consistency, and flexibility throughout the game.

Here's an overview of the system components:

  1. Scriptable Object - CollectableData The properties of each collectable, such as its name, value, and type, will be stored in a Scriptable Object, which allows for efficient data management. Using Scriptable Objects ensures that collectables sharing the same data can reference a single instance, rather than duplicating data across multiple objects.

  2. Component - Collectable The Collectable class will be a simple component added to any object to turn it into a collectable. The key function of this class is to manage the "on collection" behavior, such as updating player stats or inventory when the item is collected.

  3. Collector - Collecting Collectables The Collector class handles the interaction between the player (or another object, such as a harvester) and collectables. When a player or harvester collects an item, this class will trigger the collectable's OnCollected method.

  4. Manging Collectables - Collection The Collection class will track and manage the items that have been collected. This is particularly useful in games where resources need to be tallied, such as keeping track of how much wood, stone, or metal has been collected in a resource management game.

Collectables as a System

By approaching collectables as a system, we ensure the following benefits:

  • Consistency: All collectables follow a uniform structure, from how their data is stored (in Scriptable Objects) to how they behave when collected.

  • Reusability: Components like the Collectable and Collector can be reused across various types of collectables and collectors, ensuring flexibility and reducing redundancy.

  • The use of Scriptable Objects for collectable data centralizes shared information, minimizing memory usage and improving performance.

This structured system for handling collectables not only simplifies the development process but also provides the flexibility to expand or customize the behavior of collectables as needed throughout the game.