codeAPI Reference

s&box DamageInfo: Extensible Damage Data Class and IDamageable Interface

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

s&box DamageInfo: Extensible Damage Data Class

DamageInfo is a class (not a struct) so it can be subclassed for game-specific damage types.

Definition

CSHARP
[Expose]
public class DamageInfo
{
    public GameObject Attacker { get; set; }  // Player, NPC, etc.
    public GameObject Weapon { get; set; }    // Weapon, vehicle, etc.
    public Hitbox Hitbox { get; set; }        // Hit hitbox (if any)
    public float Damage { get; set; }         // Amount of damage
    public Vector3 Origin { get; set; }       // Source position (shooter eye, explosion center)
    public Vector3 Position { get; set; }     // Hit position on the target
    public PhysicsShape Shape { get; set; }   // Hit physics shape (if any)
    public TagSet Tags { get; set; }          // Damage type tags
}

Usage

CSHARP
// Create damage info
var dmg = new DamageInfo(damage: 25f, attacker: attackerGO, weapon: weaponGO)
{
    Origin = eyePosition,
    Position = hitPosition,
    Shape = traceResult.Shape,
    Hitbox = traceResult.Hitbox
};

// Tag-based damage types
dmg.Tags.Add("bullet");
dmg.Tags.Add("explosion");
dmg.Tags.Add("fire");

// Apply to a damageable component
var damageable = hitGO.Components.Get<Component.IDamageable>();
damageable?.OnDamage(dmg);

IDamageable Interface

CSHARP
public interface IDamageable
{
    void OnDamage(in DamageInfo damage);
}

// Implement on any component
public class Health : Component, Component.IDamageable
{
    public float HP { get; set; } = 100f;
    
    public void OnDamage(in DamageInfo damage)
    {
        if (IsProxy) return;
        HP -= damage.Damage;
        if (HP <= 0) Die();
    }
}

Subclassing

CSHARP
// Create game-specific damage types
public class BulletDamageInfo : DamageInfo
{
    public float Penetration { get; set; }
    public float Range { get; set; }
    
    public BulletDamageInfo(float damage, float penetration) : base()
    {
        Damage = damage;
        Penetration = penetration;
        Tags.Add("bullet");
    }
}

Notes

Was this helpful?