Class EntityCore
- Namespace
- ElectricDrill.AstraRpgFramework
- Assembly
- com.electricdrill.astra-rpg-framework.Runtime.dll
The core component for any entity in the game. It is the mandatory base class for all entities, providing essential functionality. Provides easy access to the entity's level, stats, and attributes.
[DisallowMultipleComponent]
public class EntityCore : MonoBehaviour, IEditorValidatable, IInvalidatable, IStatReader, IValueContainer<StatSO>, IAttributeReader, IValueContainer<AttributeSO>, ITaggable, IHasEntity, IEventRegistrar
- Inheritance
-
objectEntityCore
- Implements
- Extension Methods
Properties
Attributes
Gets the EntityAttributes component which manages the entity's attributes.
public virtual EntityAttributes Attributes { get; }
Property Value
Entity
The primary EntityCore associated with this object. For entity components this is the owning entity; for context payloads this is the primary affected subject (e.g. the event target).
public EntityCore Entity { get; }
Property Value
Level
Gets the EntityLevel class which manages the entity's level and experience.
public virtual EntityLevel Level { get; }
Property Value
Name
Gets the name of the entity's GameObject.
public string Name { get; }
Property Value
- string
Owner
Experimental — this API may still change.
The entity that owns this entity (e.g. a ship owning a turret, or a character owning a
summoned pet). null for unowned, flat entities — the default for every existing
project. Runtime-settable so pooled entities can assign it on spawn.
public EntityCore Owner { get; set; }
Property Value
Remarks
The setter refuses an assignment that would create a cycle (self-assignment or
value already being (transitively) owned by this entity) and logs an error instead.
Unity's fake-null makes this read as null once the owner is destroyed; pooled
entities must reassign Owner on respawn.
OwnerResolution
Experimental — this API may still change. How Owner is resolved when nothing was assigned explicitly. Defaults to Explicit.
public OwnerResolution OwnerResolution { get; set; }
Property Value
Remarks
Only read once, in Awake, so assigning it later has no effect on an entity that is
already awake — set it on a deactivated instance during spawn setup, or assign
Owner directly. Exposed so this piece of authored state can be read back and
restored like every other serialized field; the inspector was previously the only way to
reach it.
Root
Experimental — this API may still change. Walks up the Owner chain and returns the topmost entity. Returns this entity when it is unowned. The walk is capped at ElectricDrill.AstraRpgFramework.EntityCore.MaxOwnerChainDepth so a cycle forced through the serialized field cannot hang.
public EntityCore Root { get; }
Property Value
SaveId
This entity's stable save identity, or Empty when none was assigned. Purely a hook for an external save system: the framework never reads it, and an entity without one behaves exactly the same in every respect.
public EntitySaveId SaveId { get; }
Property Value
Remarks
Instantiate() copies a baked id. Every runtime instance of a prefab that already
carries an id shares that id. Any spawner producing entities that need independent save
identity must call RegenerateSaveId() right after Instantiate() — there
is no automatic runtime registry, because paying a lookup on every spawn (projectiles,
VFX, pooled objects) for a feature most entities never use is not a trade the framework
makes. See Documentation~/SaveSystems.md.
Stats
Gets the EntityStats component which manages the entity's stats.
public virtual EntityStats Stats { get; }
Property Value
Tags
The tags associated with this object.
public GameTagSet Tags { get; }
Property Value
Methods
Awake()
protected virtual void Awake()
EnsureSaveId()
Returns this entity's SaveId, minting one first if it is empty. Idempotent: an entity that already has an id keeps it.
public EntitySaveId EnsureSaveId()
Returns
- EntitySaveId
The entity's save id, guaranteed non-empty.
Invalidate()
Marks this object as invalid and raises OnInvalidated.
public void Invalidate()
IsOwnedBy(EntityCore)
Experimental — this API may still change.
Returns true when other is found while walking up this
entity's Owner chain (i.e. other owns this entity,
directly or transitively). Returns false for null or this.
public bool IsOwnedBy(EntityCore other)
Parameters
otherEntityCore
Returns
- bool
RegenerateSaveId()
Replaces this entity's SaveId with a freshly minted one, unconditionally.
The call a spawner makes after Instantiate() so pooled or duplicated entities do not
inherit the prefab's baked id. Discards the previous id, invalidating any save record that
referenced it.
public EntitySaveId RegenerateSaveId()
Returns
- EntitySaveId
The newly minted save id.
SetSaveId(EntitySaveId)
Re-applies a previously saved SaveId, e.g. while restoring an entity from save data. Accepts any value, including Empty and an id already carried by another live entity: uniqueness is the save system's concern, not the framework's, and refusing a write here would only leave a restore half-applied.
public void SetSaveId(EntitySaveId id)
Parameters
idEntitySaveIdThe save id to apply.
Start()
protected virtual void Start()
Subscribe<TEvent>(TEvent)
Registers gameEvent on the channel matching TEvent.
public void Subscribe<TEvent>(TEvent gameEvent) where TEvent : ScriptableObject
Parameters
gameEventTEvent
Type Parameters
TEvent
Exceptions
- ArgumentException
Thrown when no channel is registered for
TEvent.
Unsubscribe<TEvent>(TEvent)
Removes gameEvent from the channel matching TEvent.
public void Unsubscribe<TEvent>(TEvent gameEvent) where TEvent : ScriptableObject
Parameters
gameEventTEvent
Type Parameters
TEvent
Exceptions
- ArgumentException
Thrown when no channel is registered for
TEvent.
Update()
protected virtual void Update()
Events
OnBeforeSpawned
Raised after all EntityCore initialization is complete (level, stats, attributes) but
before the spawned event is broadcast. Sibling components that need to run logic tied
to entity spawn — such as applying innate modifiers — should subscribe to this event
in their Awake() instead of relying on script execution order.
public event Action OnBeforeSpawned
Event Type
- Action
OnInvalidated
Raised when this object is invalidated.
public event Action OnInvalidated
Event Type
- Action
OnOwnerChanged
Experimental — this API may still change. Raised when Owner changes, with the previous and current owner.
public event Action<EntityCore, EntityCore> OnOwnerChanged
Event Type
- Action<EntityCore, EntityCore>