🗺️ GameInstance

GameInstance – Component Overview

GameInstance is the central data manager of the Virtual Pet Game Template. It holds references to all major catalogs, rules, and settings used across the game, and is persistent across scenes.


🧾 What It Manages

Catalog References

These fields reference the game’s core data collections:

  • petData[] – List of available pets.

  • currencyData[] – List of available in-game currencies.

  • foodData[] – List of available food items.

  • minigameData[] – All mini-games available in the game.

  • petClothesData[] – Available clothing and accessories for pets.

⚠️ These are ScriptableObjects. The process of creating and editing them is covered in separate pages: [How to Add New Pet], [How to Add New Food], etc.

Game Rules

  • petRules – Defines emotional states and conditions for pet mood, based on stat thresholds.

EXP Configuration

  • initialExp – EXP required for level 1.

  • finalExp – EXP needed for the last level.

  • maxLevel – Maximum level the player can reach.

  • expProgressType – Defines how EXP scales (Linear or Exponential).

  • expPerLevel[] – Auto-filled array defining exact EXP per level (editable in inspector).


📦 Runtime Methods

Pet & Food Access

  • GetPetDataById(int id) – Finds a pet by its ID.

  • GetFoodDataById(int id) – Finds a food item by its ID.

  • GetMaxStatValueById(int petId, string statId) – Retrieves the max value of a stat for a given pet.

Mood Logic

  • GetCurrentPetMood() – Returns the current mood string ID for the selected pet based on rules and current stats.

Instantiating Pets

  • InstantiatePetModel(Transform container) – Instantiates the currently selected pet prefab inside a container.

UI Helpers

  • GetCurrencyIconById(string id) – Returns a Sprite icon for the currency.

  • GetTranslatedString() – Helper functions for fetching localized strings from translation arrays.


💡 Editor Integration

  • Includes a custom inspector to auto-fill the EXP table (expPerLevel[]) based on chosen curve type.

  • Shows current pet mood when in play mode (for debugging).


This component should only exist once in the project and is marked as DontDestroyOnLoad. It acts as the backbone of all catalog and rule-based access across the game.

Last updated