PROLOGUE
For me, the hardest part of writing an article is always getting started. The system is already working, everything is clear in my head, and the architecture has been designed and implemented. But when you open a blank page, one simple question comes up: where do I even begin?
Since I can't seem to jump straight into the technical details, I'll start with something a little more personal. That's always easier.
The movie "The Matrix" touches on an interesting idea: everything around us can be thought of as computer code. Every system has its own purpose, interacts with other systems, and can still evolve independently of them.
When you think about it, even a very complex system can have a surprisingly simple foundation.
Take something as ordinary as a loaf of bread.
In the game world, bread is represented by an item, but an object is what actually keeps track of it. That's where its data, properties, and current state are stored.
The object can hold information about whether the bread is wet, dirty, hot or cold, or damaged. It can belong to a backpack, be held in a character's hands, or simply lie somewhere on the ground.
Its state can change due to external factors: rain, wind, time, falling, or physical interaction, for example.
Just like in real life.
So, an item is really just the visible representation of an object.
And that's where the idea for a new architecture for item interaction came from.
THE OBJECT AND ITS REPRESENTATION
Previously, I treated an object and its visual representation as one and the same thing. Data, state, and how something appeared in the game world were tightly connected. But over time, I realized that this approach was limiting.
An object doesn't need to have a visual representation in the game world at all times in order to keep existing.
So I decided to separate the object from its visual representation.
What exists in the system
- Has its own state
- Stores its own data
- Can contain other objects
- Exists independently of the game world
- Can be stored even when nobody can see it
What you see in the game
- Has a visual appearance
- Can move and interact with its surroundings
- Reflects the object's state
- Appears when needed
- Can be removed without affecting the object itself
A SINGLE SYSTEM CORE
One Ring to find them,
One Ring to bring them all
And in the darkness bind them.
J. R. R. Tolkien — "The Lord of the Rings"
As the number of objects grows, it's important to have a single place where information about any of them can be accessed.
The object is registered in the system and receives a unique identifier.
Other systems find the required object using its identifier.
The object's data and state can be updated independently of its visual representation.
Once its lifecycle is complete, the object is removed from the system.
This approach eliminated the need to maintain separate lists of objects in every subsystem. It minimizes the risk of duplicated data and synchronization issues, while also making it easier for different parts of the system to work together.
ONE OBJECT INSIDE ANOTHER
For example, a character has a weapon. The weapon has an optic, a muzzle device, and a magazine attached to it. The magazine contains cartridges. Each of these elements is an independent object with its own data and state.
So what we end up with is more than just a list of items. It's a hierarchical structure.
I didn't have to create a separate nesting system for every type of object. They all follow the same principle, while the specific rules — what an object can contain, where it can be placed, and which elements are available to it — are defined by its own data.
Each object also keeps its own identity and state. The magazine doesn't become part of the weapon's data, and the optic doesn't become part of some aiming system. They're independent objects that can exist separately from their current owner and change owners as the game progresses.
Items, on the other hand, represent these objects in the game world. If a weapon is in a character's hands, its visual representation appears there too. If the magazine is removed, it can get its own representation without losing its identity as the same object.
THE TRANSFER SYSTEM
A separate transaction mechanism handles object transfers and changes to the relationships between them. This prevents other systems from directly interfering with the ownership structure.
When an object moves from one container to another, the system checks whether the operation is allowed, frees up its previous slot, and establishes the new relationship. All these actions are performed together.
Installing a magazine into a weapon is also a transfer operation. The weapon's visual representation is updated only after the transfer has been completed successfully.
CREATING A REPRESENTATION
A separate representation creation mechanism determines which representation corresponds to a particular object type, creates it, and links it to the original object.
The mechanism itself doesn't need to know what the object is made up of. Its job is limited to creating and registering the representation.
When a weapon needs to appear in the game world, an item is created for it. Once initialized, it accesses the object's data, identifies its nested objects, and requests separate representations for each of them. That's how the magazine, optic, and other attachments are brought back.
ITEM DEFINITIONS
Every item has its own identity, while its base properties are defined by a shared type definition. This means there's no need to duplicate the same item definition for every instance.
These definitions are stored in JSON format. Server owners can customize existing items and create new variations by changing their properties and settings, without having to develop a separate game implementation for each one.
FIREARM CONFIGURATION JSON
[
{
"Id": "AKM",
"DisplayName": "AKM Assault Rifle",
"Model": "/Firearm/Rifle/AKM/M_AKM",
"BarrelFactor": 1.0,
"BaseSpreadMOA": 3.0,
"BarrelLength": 41.5,
"ChamberSize": 1,
"AutoChamber": true,
"AmmoSource": "DetachableMag",
"AnimTag": "Rifle",
"AnimSequences": [
"AKM_ReloadSequence",
"AKM_Unjam",
"AKM_Selector",
"AKM_MagCheck",
"AKM_ChamberCheck"
],
"Wear": {
"WearPerShot": 0.0015,
"JamChanceMultiplier": 1.0,
"CriticalWearThreshold": 0.3
},
"AcousticPropagation": {
"Begin": "/Firearm/SFX/AK_Family/S_AK_Oneshot",
"End": "/Firearm/SFX/AK_Family/S_AK_Stop",
"Tail": "/Firearm/SFX/AK_Family/S_AK_Tail",
"Range": 3000.0
},
"Magazines": ["Mag_AKM_30Rnd"],
"AmmoTypes": [
"Ammo_762x39",
"Ammo_762x39Tracer",
"Ammo_762x39Subsonic"
],
"Muzzles": ["Muzzle_PBS1"],
"Optics": ["Optic_PSO1"],
"FireModes": [
{ "Mode": "Semi", "Interval": 0.130 },
{ "Mode": "Auto", "Interval": 0.100 },
{ "Mode": "Safe" }
]
}
]
MAGAZINE CONFIGURATION JSON
[
{
"Id": "Mag_AKM_30Rnd",
"DisplayName": "Steel Magazine AK",
"Capacity": 30,
"Model": {
"MagazineMeshName": "/Firearm/Ammunition/Magazine/AK_SteelMag_30Rnd/M_AK_SteelMag_30Rnd",
"RoundMeshName": "/Firearm/Ammunition/Cartridge/762x39/M_762x39",
"RoundScale": 0.86
},
"AmmoTypes": [
"Ammo_762x39",
"Ammo_762x39Tracer",
"Ammo_762x39Subsonic"
],
"RoundLayout": {
"Location": [-0.5, -3.7, 9.45],
"Rotation": [-5.0, 0, 0],
"Spacing": [0, -0.3145, 0.97561],
"UseCurvedLayout": true,
"UseDoubleStack": true,
"SideOffset": [1, 0.2, -0.6],
"YawAngle": -3.0,
"CurveIntensity": 1.35,
"CurveRotationCompensation": [-16, 0, 0],
"CurveAxis": [0, -1, 0],
"ExcludeFirstRoundFromCompression": false
}
}
]
MUZZLE DEVICE CONFIGURATION JSON
[
{
"Id": "Muzzle_PBS1",
"DisplayName": "PBS-1 Suppressor",
"Model": "/Firearm/Device/Muzzle/PBS1/M_PBS1",
"Type": "Suppressor",
"RecoilMultiplier": 0.9,
"BarrelExtension": 15.0,
"AcousticPropagation": {
"Begin": "/Firearm/SFX/AK_Family/S_PBS1_Oneshot",
"End": "/Firearm/SFX/AK_Family/S_PBS1_Stop",
"Tail": "/Firearm/SFX/AK_Family/S_PBS1_Tail",
"Range": 300.0
},
"Temperature": {
"MaxCelsius": 427.0,
"IncreasePerShot": 3.3
},
"Resource": {
"Type": "Restorable",
"PassiveRate": -0.003981
}
}
]
OPTIC CONFIGURATION JSON
[
{
"Id": "Optic_PSO1",
"DisplayName": "PSO-1 Optical Sight",
"Model": "/Firearm/Device/Optic/PSO1/M_PSO1",
"Magnifications": [4.0],
"ZeroingDistances": [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
"Reticle": {
"Texture": "/Firearm/Device/Optic/PSO1/T_PSO1_Reticle",
"Brightness": 1.0
}
}
]
This approach doesn't limit the system to a predefined set of types. Server owners can create their own item variations while keeping the same underlying principles for identification, storage, ownership, and persistence.
SAVING AND RESTORATION
The persistence system works directly with object data. It uses a custom binary protocol: an object's state is serialized for storage and reconstructed when loaded.
It doesn't matter whether we're dealing with a weapon, a magazine, a cartridge, or an entirely new item added by a server owner. The system handles data as a universal sequence of bytes without interfering with its internal structure.
Once loaded, objects are registered in the system again with their original identifiers and states. Their relationships with other objects are restored as well, while visual representations are created only where they're needed.
CONCLUSION
In the end, I got exactly what I was aiming for: one Ring to rule them all. Now I can move on to the next thing.
There's still a lot of work ahead, and the system will gradually become more complex. But what's important to me is keeping the original idea intact: clear separation of responsibilities, with each part remaining understandable, manageable, and as independent as possible.