🐾 How to Add a New Pet
This guide explains how to create, configure, and register a new pet in the Pet Care system using PetData, PetModel, and integration with food preferences.
🧱 Step 1 – Create a New PetData Asset
PetData AssetIn Unity, go to the Project tab.
Right-click in your desired folder →
Create > PetCareGame > Pet Data.This creates a new ScriptableObject with default values.
Fill Out the Fields
petId
Unique ID used to identify the pet (must be different from others).
petIcon
Sprite to show in selection menus or UI.
petName
Translated name per language.
petDescription
Translated short description.
petStats
Initial values for stats like health, energy, hygiene, etc.
petModel
Reference to the 2D or 3D model prefab containing the PetModel component.
🎨 Step 2 – Setup the Visual Prefab (PetModel)
PetModel)Create or duplicate a pet prefab (2D or 3D) and configure it:
Add the
PetModelcomponent to the root GameObject.Choose the model type:
Model2DorModel3D.Configure the body renderers:
For 2D: Assign
SpriteRenderer[]inbodyRenderer2D.For 3D: Assign
Renderer[]inbodyRenderer3Dor usechangeMaterialfor shared material tinting.
Add facial expressions for each mood:
Define unique
idvalues (e.g.,happy,sad,angry).Link associated GameObjects (eyes, mouth, etc.) that visually reflect that mood.
Configure:
Optional LeanTween animation settings.
Optional animation clips and audio feedback.
👉 Drag this prefab into the petModel field in the PetData asset.
🧢 Equipping Accessories (Hats, Glasses, etc.)
The PetModel prefab includes a section called Objects to Activate, which controls visual GameObjects linked to equipped cosmetic items such as hats, glasses, bows, etc.
Structure Overview
Each entry in this list defines:
slotId: A slot type like"hat","glasses","bow"items: A list of item IDs and associated GameObjects for that slot
How It Works
At runtime, the system checks which item is equipped using:
It will then:
Activate the objects for the matching
itemIdDeactivate all others in the same slot
Example
If the player equips a hat with ID "hat_blue_cap":
PlayerSave.SetSelectedClothes("hat", "hat_blue_cap")is called.At startup or refresh,
PetModel.ApplyEquippedClothes()will:Look for a
CharacterObjectsentry withslotId = "hat"Find a
CharacterObjectwhereitemId = "hat_blue_cap"Activate the assigned GameObjects only for this item
If no item is selected for a slot, all GameObjects in that slot are hidden.
🍎 Step 3 – Configure Food Preferences (Optional)
To personalize how much a pet likes specific foods:
Open each
FoodDataasset in your project.Find the section
Pet Preferences.Add a new entry for the pet you just created.
If no preference is registered for a pet, the system applies a default acceptance chance defined internally.
Step 4 – Add to GameInstance
In the home scene, select the GameInstance component and add the new PetData in the PetData field.
✅ Final Checklist
🧪 Runtime Notes
At runtime, the selected pet is determined by:
The system uses this to:
Spawn the visual model
Access max stats for decay logic
Match food preferences
Handle equipped clothes and color tint
🧩 Sample Code
💡 Tips
You can reuse animations and materials across pets to reduce memory.
Consider adding unique sounds or accessories per pet.
Use meaningful
petIdvalues like0 = Cat,1 = Dog, etc.
Last updated