Damage Processor - Originator Setup

SaeDus

New member
I am working on a project with the UCC and PUN (with the integration tool) and I have been trying to setup a custom Damage Processor with no luck at all. I have read up on the documentation for what it does, but it seems to do little on explaining how to setup the system. No matter how I try to set it up, the weapon on the character refuses to send anything other than just the amount of damage to deal. I had this setup originally with an older version of UCC so each player character would process the "attacker" data when they took damage so that it would prevent friendly fire while allowing healing abilities to aid their allies. After updating to 2.4.3, everything broke down and I am unable to send the Damage Originator to the target character -- it only ever sends the damage amount while leaving the Owner blank.

This is my code for the custom Damage Processor which is added to the character's Damage Processor Module. I found a forum post demonstrating the Damage Processor for the "Adventure" and tried to use that as a template.

C#:
namespace Characters
{
    [CreateAssetMenu(
        fileName = "TestingDamageProcessor",
        menuName = "Ultimate Character Controller/Damage Processors/Testing Damage Processor")]
    public class TestingDamageProcessor : DamageProcessor
    {
        private GameObject _originator;
     
        private int _originFaction;
     
        public class NewDamageData : DamageData
        {
            public int Faction;

            public override void Copy(DamageData damageData)
            {
                base.Copy(damageData);

                if (damageData is NewDamageData newDamageData)
                 
                    Faction = newDamageData.Faction;
            }
        }

        private NewDamageData _newDamageData = new NewDamageData();
     
        public override void Process(IDamageTarget target, DamageData damageData)
        {
            _newDamageData.Copy(damageData);

            var newOriginator = new DefaultDamageOriginator
            {
                Owner = _originator
            };

            _newDamageData.DamageOriginator = newOriginator;

            _newDamageData.Faction = _originFaction;

            target.Damage(_newDamageData);
        }

        public void InitializeProcessor(GameObject attacker, int faction)
        {
            _originator = attacker;

            _originFaction = faction;
        }
    }
}


When a player selects a character, they are spawned into the game where they will then run this code:

C#:
private DamageProcessorModule _damageModule;

private void SetupDataProcessor()
{
    var o = gameObject;
         
    var myFaction = o.GetComponent<Respawner>().Grouping;
         
    if (_damageModule.DefaultDamageProcessor is TestingDamageProcessor defProcessor)
             
        defProcessor.InitializeProcessor(o, myFaction);
}

I have thrown Debug.Logs into many different parts of the code -- including in the InitializeProcessor method to check that the private "_originator" and "_originFaction" variables are being set (which they are). When I jump into the game and shoot another player, the Debug.Log within the CharacterHealth component always states the damage amount but the originator is always blank.


The documentation states that every weapon will use the same Damage Processor component that is set on the character's Damage Processor Module, but that didn't seem to be the case (or I am just not setting up the Damage Originator properly). I then tried to copy the Default Damage Processor directly to the Shootable Weapon using the following code (called after initializing the Damage Processor on the character's Damage Processor Module):

C#:
[SerializeField] private ShootableWeapon _weapon;

private void SetupItemProcessor()
{
    _weapon.DamageProcessor = _damageModule.DefaultDamageProcessor;
}

This still leaves the Damage Originator blank any time the character is hit. Again, I am just trying to access the Damage Originator and a custom int to indicate which team the character is on. I know I am just missing something with how the Damage Processors are setup or handled, but I cannot find any more information on how to setup the Damage Originator. The documentation simply states, "The [Damage Originator] Owner can be the player character," which is what I am trying to establish.

Note: I am using Ultimate Character Controller 2.4.3, PUN Multiplayer Add-On 1.1.15, and Unity version 2020.2.5f1.
 
Last edited:
Hi,

the point of confusion might be that the damage processor is evaluated on the attacker, not the target / hit character. If a damage processor is set on the attacker character, this processor will be used. If there is no processor on the character, it looks for a processor on the weapon. If none is set, the default processor is used. The originator is set automatically on the melee or shootable weapon, so you don't have to set it manually. I still checking with Justin whether there is a bug in running the processor.
 
I have it setup so that all the code I posted is attached to the attacking character -- by creating the new TestingDamageProcessor in the Create Asset Menu and attaching it to the attacking character's prefab's Damage Processor Module (then the other tests were done just to directly add the Damage Processor to the Item to no avail). When the target character is hit, their Health component will check the Damage Processor to try to get the Damage Originator so that I can check if the attacker is a friendly, using a healing ability, etc.

Everything that I posted has been done on the attacking character (and I even setup the target character with the same Damage Processor just to see if I had it backwards), but the character's Health component always receives the correct Amount and is missing a reference to the Damage Originator and Owner.


Edit: I have tried using the Damage Originator before setting it manually the way I have it setup in my original post, but after not seeing it pass to the target, that's when I tried manually assigning it and checking if the target would receive that information.

I do want to thank you for taking the time to look into this, too.
 
Last edited:
The originator isn't set correctly with the PUN add-on, this post is related:


Beyond that, @ChristianWiele was debugging this and the OnObjectImpact event is triggered before the processor is ran. Are you using this event?
 
I created a custom Health component that inherits from CharacterHealth and overrides the OnDamage(DamageData) method where I perform the checks for the Damage Originator. I am not using the OnObjectImpact event at all.
 
Have you tried a fresh project? In the demo scene when the agent is hit the damage indicators appear which uses the originator.
 
I just loaded it up in a fresh project, and the damage indicator does work properly. I apologize for not trying that first, and now I know that it's nothing wrong with the controller. Thanks for the reply!
 
Top