Game.Damage
Assembly:
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
Represents a discrete damage event targeting another entity. Stores a reference to the target entity and a damage vector (float3) describing the damage delta. This is a plain ECS component suitable for adding to entities to convey damage information to systems or jobs.
Fields
-
public Unity.Entities.Entity m_Object
The target object (entity) that this damage applies to. Use this to identify which entity should receive or process the damage. -
public Unity.Mathematics.float3 m_Delta
The damage vector containing the change/amount of damage. float3 is commonly used for directional or multi-channel damage values (for example, separate damage values per axis or to carry extra metadata).
Properties
- This type does not declare any properties. It uses public fields for data.
Constructors
public Damage(Unity.Entities.Entity _object, Unity.Mathematics.float3 delta)
Initializes a new Damage component with the specified target entity and damage delta.
Methods
- This struct does not declare any methods. It is a plain data component used with the ECS.
Usage Example
// Create a Damage component and add it to an entity using EntityManager
using Unity.Entities;
using Unity.Mathematics;
using Game.Objects;
public void ApplyDamage(EntityManager entityManager, Entity target, float3 damageDelta)
{
var damage = new Damage(target, damageDelta);
// Either add as a component to an entity that will process it:
entityManager.AddComponentData(target, damage);
// Or write it to a "damage sink" entity that systems read from:
// entityManager.AddComponentData(damageSinkEntity, damage);
}
// Example in a system using EntityCommandBuffer (thread-safe in jobs)
public partial struct DamageSpawnSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
Entities.ForEach((Entity e) =>
{
// Create damage for some target (example)
var dmg = new Damage(targetEntity, new float3(10f, 0f, 0f));
ecb.AddComponent(e, dmg);
}).Run();
ecb.Playback(state.EntityManager);
ecb.Dispose();
}
}
Notes and recommendations: - Because Damage implements IComponentData, it is a value-type component and cheap to copy. Use it directly in jobs/systems. - IQueryTypeParameter allows this type to be used in queries and high-level ForEach patterns where supported. - Consider whether damage should be transient (added/removed each frame) or accumulated on a persistent component; choose the entity/component lifecycle accordingly.