Skip to content

Game Database

The game database is the list of everything your game is made of: the character prefabs players control, the monsters, the items and skills, the maps, the quests. Clients and servers look content up by ID, and only content that has been registered can be found. An item that never reaches the database can’t drop, can’t be bought and can’t be loaded from a saved character.

A game database has two kinds of entry.

The demo's Game Database asset in the Inspector, with its Entity and Game Data lists and the number of entries in each.

Entities are the prefabs that appear in the world and are synchronised over the network:

EntryWhat it is
Player Character EntitiesThe character prefabs players control.
Monster Character EntitiesMonster prefabs.
Vehicle EntitiesMounts and vehicles players can ride.
Other Network ObjectsAny other networked prefab the game spawns.

If your project uses Addressables, each list has an Addressable twin that holds asset references instead of prefabs. See Before you build.

Game data are the ScriptableObject assets that describe your content:

EntryWhat it is
AttributesStats that stat points can raise, such as Strength or Vitality.
CurrenciesCurrencies other than gold.
Damage ElementsKinds of damage, such as fire or poison, each with its own resistances.
ItemsEvery item, of every type.
Item Craft FormulasCrafting recipes.
Armor Types, Weapon Types, Ammo TypesThe categories items belong to. A weapon type decides how its weapons attack and which ammo they use; an armor type decides which slot it fills.
SkillsCharacter skills, active and passive.
Player Icons, Frames, Backgrounds, TitlesProfile cosmetics players can choose from.
Guild Skills, Guild IconsSkills a guild can learn, and crests a guild can pick.
Status EffectsBuffs and debuffs that attacks and skills can apply.
Player CharactersThe playable classes.
Player Character Entity Meta DataA variant of a player character prefab: which classes are offered with it at character creation, and its race.
Monster CharactersMonster data: stats, skills, rewards and drops.
HarvestablesResources such as trees and ore, and what they yield.
Map InfosEach map scene a player can be on, with its rules.
QuestsQuests.
FactionsSides players can choose, if your game has them.

You don’t have to list everything by hand. When the game loads an entry, it also registers the data that entry refers to. Registering a monster also registers its skills and the items it drops. Registering a class also registers its attributes and the damage elements its armour resists. Registering a character or monster prefab also registers its character data, and with it everything above. In practice you register the top of each chain, and the rest follows.

Game Database holds its lists in the asset itself. You add entries by dragging assets into its fields, or with the Game Database window. It loads exactly what you list, plus the related data, so you always know what’s in the game.

  • Create: in the Project window, right-click and choose Create → Create GameDatabase → Game Database.

Resources Folder Game Database has no lists. It loads every asset of each supported type from any Resources folder in the project, so creating an asset in one of those folders is enough to register it. That’s convenient, but everything under Resources goes into every build whether the game uses it or not.

  • Create: Create → Create GameDatabase → Resources Folder Game Database.

The demo uses a Game Database: Assets/OpenMMORPG/Demo/GameData/GameDatabase.asset.

Drag your database into the Game Database field of Game Instance. If you leave that field empty, the game falls back to loading game data from Resources folders, the same way a Resources Folder Game Database does.

The Game Database field on the demo's Game Instance, highlighted, holding the demo's GameDatabase asset.

Tools → Open MMORPG → Develop → Game Database opens a window for managing a Game Database’s contents. When it opens, it asks which Game Database to edit. To switch to another one, close the window and open it again. The Open Manager button at the bottom of a Game Database’s Inspector does the same thing for that database.

The Game Database window with the demo's database open: kinds of data on the left, the demo's items in the middle, and the Iron Longsword open for editing on the right.

The left column lists kinds of data, the middle column lists the entries of the selected kind by ID and file name, and the right side edits the selected entry in place. Along the top:

  • Create makes a new asset of the selected kind and adds it to the database.
  • Duplicate copies the selected entry’s asset and adds the copy.
  • Delete removes the selected entry and deletes its asset file from the project.
  • Adding Unlisted Data is for an asset that exists but isn’t in the database yet. Drop it into that field, and an Add button appears.

The window covers the most common kinds of data, not every list. Edit the others, such as the entities and the player icons, frames, backgrounds and titles, on the database asset in the Inspector. The window works with Game Database assets only, because a Resources Folder Game Database has no lists to manage.

If neither kind suits you, for example because you want to load data from your own files or a web service, write your own. Make a class that inherits from BaseGameDatabase and implement LoadDataImplement. In it, register your data with the GameInstance.Add... methods:

using Cysharp.Threading.Tasks;
using UnityEngine;
namespace MultiplayerARPG
{
[CreateAssetMenu(fileName = "My Game Database", menuName = "Create GameDatabase/My Game Database")]
public class MyGameDatabase : BaseGameDatabase
{
public BasePlayerCharacterEntity[] playerCharacterEntities;
public BaseItem[] items;
protected override UniTask LoadDataImplement(GameInstance gameInstance)
{
GameInstance.AddPlayerCharacterEntities(playerCharacterEntities);
GameInstance.AddItems(items);
return UniTask.CompletedTask;
}
}
}

LoadDataImplement returns a UniTask, so it can also be async and await data that takes time to arrive.

There is an Add... method for every kind of entry, including:

  • Entities: AddPlayerCharacterEntities, AddMonsterCharacterEntities, AddVehicleEntities, AddOtherNetworkObjects, plus AddAssetReference... versions of each for Addressables.
  • Game data: AddAttributes, AddCurrencies, AddDamageElements, AddItems, AddItemCraftFormulas, AddArmorTypes, AddWeaponTypes, AddAmmoTypes, AddSkills, AddPlayerIcons, AddPlayerFrames, AddPlayerBackgrounds, AddPlayerTitles, AddGuildSkills, AddGuildIcons, AddStatusEffects, AddCharacters (for both player and monster characters), AddPlayerCharacterEntityMetaDataList, AddHarvestables, AddMapInfos, AddQuests, AddFactions, AddNpcDialogs, AddEquipmentSets.

Each Add... method also registers the related data of what it adds, the same way the built-in databases do.