When to use an Entity or a plain class
Keep an object out of the hierarchy when it only needs data and computation.
Choose by responsibility
| Required capability | Use |
|---|---|
| Parent, children, _Ready, input or frame callbacks | Entity or a suitable subclass |
| A 2D or 3D transform | Entity2D or Entity3D |
| Shared editable and persistable configuration | Resource |
| Health rules, purchase cost or data conversion | A plain C# class or method |
| Many homogeneous numbers for computation | A suitable collection rather than an Entity per number |
HealthModel below does not depend on the engine. Create, call and test it without a level, path or _Ready. IDamageable defines the available command.
HealthModel.cs
using System;
public interface IDamageable
{
bool TryApplyDamage(int amount);
}
public sealed class HealthModel : IDamageable
{
public int Maximum { get; }
public int Current { get; private set; }
public HealthModel(int maximum)
{
if (maximum <= 0) throw new ArgumentOutOfRangeException(nameof(maximum));
Maximum = maximum;
Current = maximum;
}
public bool TryApplyDamage(int amount)
{
if (amount <= 0 || Current == 0) return false;
Current = amount >= Current ? 0 : Current - amount;
return true;
}
}When an Entity wrapper is useful
DamageReceiver in the complete example connects the model to lifecycle, exported settings and an engine signal. Separate these responsibilities where it makes the code clearer; not every property needs its own interface and class.
A plain C# object is not automatically serialized by PackedEntity. Save the required values through a separate schema if they must survive quitting the game.
Entity here means a hierarchy object. The name does not imply ECS, dense component storage or automatic large-world processing. Choosing a class alone proves no speedup: measure the actual workload.