ImpactDamageData is Null

magique

Active member
I'm using the new OnObjectImpact event and with all weapons except for the arrow projectile, when I receive a callback on this event, the ImpactDamageData is always null. What do I need to do to get swords and other melee weapons to have non-null damage?

Also, shooting guns causes no Impact event at all to be called. How do we receive an event when a bullet hits the target so we can apply damage?
 
Ok, so for me to get this to work with guns, I had to add the following line of code in HitscanShooter.cs at line 115:

m_ShootableImpactCallbackContext.ImpactDamageData = new ImpactDamageData();

And for the gun, had to add ImpactEvent and also change SimpleDamage to use Context Data. I'm still trying to figure out the melee weapons like sword. Perhaps the ImpactDamageData is not being initialized for them either? Of course, it's entirely possible that there's some other way of getting the controller to use ImpactDamageData, but I have not found it yet.
 
For melee weapon, had to change CollisionModule.cs on line 269 adding this code before return statement:

impactCallbackData.ImpactDamageData = new ImpactDamageData();

I still think there must be a proper way for these to get initialized, but haven't found it.
 
Hey,
ImpactDamageData is optional and is null by default. It is there in case you want to add some custom data for your damage.

In most cases we use the SimpleDamage ImpactAction
which uses the ImpactCollisionData to compute the damage within a DamageProcessor. And it damages the Health component directly.

If you want to use the ImpactDamageData to contain custom data you can inherit the IImpactDamageData with your custom class and use it from there. And then you can use a custom module or impact action to make use of that custom data.

In our use cases, we use the ImpactDamageData to tell the weapon the damage on a projectile or explosion, this way the weapon can indirectly post-process the damage.

I hope that makes sense.
 
I'm not sure I follow this. In the previous version, we could simply register for OnObjectImpact and it would have the damage value included. But now that is no longer the case and it sounds like we have to add custom code to get at the damage value for OnObjectImpact. Is there some way to get the damage amount without making any changes to code or providing custom solutions?
 
Hi @magique ,
Another person also made the same remark. So I decided to change the SimpleDamage ImpactAction a bit to make it easier to use with OnObjectImpact

Please find the new script attached.

You can now use the "SetDamageImpactData" option which I made true by default
I also added a "InvokeOnObjectImpact" option, so that you don't even have to add the "ImpactEvent" ImpactAction to the list
In addition the SimplDamageData will potientially send the event to 3 places (ONLY if they are not the same, so that you do not receive duplicate events on the same gameObject): on the Collider, on the attached Rigidbody and on the Target.

1670502046804.png

I really hope that helps makes things easier to use. Do let us know if you have additional suggestions
 

Attachments

  • SimpleDamage.cs
    14.2 KB · Views: 10
Thanks. That works perfect. I can use the same script, but just don't have to modify code or do all the extra stuff now.
 
Top