reckfellENGINE

When to use an Entity or a plain class

Keep an object out of the hierarchy when it only needs data and computation.

On this page

Choose by responsibility

Required capabilityUse
Parent, children, _Ready, input or frame callbacksEntity or a suitable subclass
A 2D or 3D transformEntity2D or Entity3D
Shared editable and persistable configurationResource
Health rules, purchase cost or data conversionA plain C# class or method
Many homogeneous numbers for computationA 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
C#
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.

Where data belongs · Entity and types

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.