Damage Processor

The Damage Processor is a Scriptable Object that allows you to customize how damage is computed between a Damage Originator (such as a Melee Weapon or Projectile) and a Damage Target (such as the object’s Health).

If not specified all weapons will use the default Damage Processor which deals simple damage. A custom Damage Processor can be created and set on the Character via a Damage Processor Module or individually on each weapon. It can also be used in other scenarios where an object can deal damage without any weapons. The main use case for having a custom Damage Processor is to compute damage using an external stat and modifier system.

The Damage Processor component can be set on the character GameObjects allowing all weapons to use the same Damage Processor.

The Damage Processor can also be set on the items individually. The Damage Processor field can be found under the Impact section.

The Damage Processor system is broken down in multiple parts.

Damage Processor

The Scriptable Object where you can define how to compute the damage dealt to an object.

To create a custom Damage Processor simply inherit the class and override the Process function

[CreateAssetMenu(fileName = "MultiplierDamageProcessor", menuName = "Ultimate Character Controller/Damage Processors/Multiplier Damage Processor")]
public class MultiplierDamageProcessor: DamageProcessor
{
	[SerializeField] protected float m_Multiplier;

	/// <summary>
	/// Processes the DamageData on the DamageTarget.
	/// </summary>
	/// <param name="target">The object receiving the damage.</param>
	/// <param name="damageData">The damage data to be applied to the target.</param>
    public override void Process(IDamageTarget target, DamageData damageData)
    {
		damageData.Amount *= m_Multiplier;
		target.Damage(damageData);
    }
}

Damage Originator

The Damage Originator is an interface. It can be used to define the object that is dealing the damage.

/// <summary>
/// Specifies an object that can cause damage.
/// </summary>
public interface IDamageOriginator
{
    // The GameObject that causes damage.
    GameObject Owner { get; }
    // The GameObject that originates the damage. This can be different from the Owner in that it can be the IUsableItem.
    GameObject OriginatingGameObject { get; }
}
  • The Owner can be the player character
  • The OriginationGameObject can be the Weapon

Damage Target

The Damage Target is an interface. It can be used to define the object being hit.

/// <summary>
/// Specifies an object that can receive damage.
/// </summary>
public interface IDamageTarget
{
    // The GameObject that receives damage.
    GameObject Owner { get; }
    // The GameObject that was hit. This can be a child of the Owner.
    GameObject HitGameObject { get; }
    /// <summary>
    /// Damages the object.
    /// </summary>
    /// <param name="damageData">The damage received.</param>
    void Damage(DamageData damageData);
    /// <summary>
    /// Is the object alive?
    /// </summary>
    /// <returns>True if the object is alive.</returns>
    bool IsAlive();
}

The Owner can be the character and the hit GameObject contains the collider that was hit.

Damage Data

The damage data is a compilation of all the information required to decide how the damage should be computed.

  • Damage Originator: The Object that caused the damage.
  • Damage Target: The Object that is being damaged.
  • Amount: The amount of damage to deal in floats.
  • Position: The position of the hit.
  • Direction: The direction of the hit.
  • Force Magnitude: The force magnitude of the hit.
  • Frames: The number of frames that the force should be applied over.
  • Radius: The radius of the force.
  • Hit Collider: The collider that was hit.
  • User Data: Any additional user data that should be taken into account when using a custom Damage Processor.

The User Data property is quite useful when using a custom Damage Processor.