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.
When a player selects a character, they are spawned into the game where they will then run this code:
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):
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.
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: