Reference to Gun Through Projectile?

AlexM

New member
Hi there!

I was trying to get my custom damage processor working, and I noticed that the DamageOriginator in the DamageData was referencing the Projectile script on the bullet. This is fine for me, but I also need to get the gun the bullet was fired from. I can't seem to find any reference to the gun anywhere on the projectile, though.

Additionally, I have the damage processor attached to the character itself, rather than on the weapons. While this works fine for melee and hitscan shooter, it only works for projectile shooter after I add the same damage processor to the gun. This isn't much of a problem, but I thought was strange. Does this mean that the default processor is being added to the bullet on its spawn, which then cancels out my custom processor?

Thank you, and sorry if this question was already asked! I was looking around, but couldn't find anything that addressed this.
 
The damage processor on the projectile is set by the shootable weapon if it is not null. Otherwise the projectile's damage processor is initialized to the default processor. So on your shootable weapon you should add a processor that sets the originator to the weapon. This way you should be able to get the weapon from the projectile.
 
Thanks for the reply! I guess my next question is, how would I go about doing that? For my case, it's important to have a reference to both the bullet and the gun on the processor, since they each have different damage values that get added together ( i.e. a gun can use both "Fire Bullets" and "Ice Bullets" ). I'll attach my current script here so you can see what I mean. I know now that it isn't exactly the correct solution, but maybe you could see what I was trying to get at with it.

As a side note, I'm using the UIS integration to do this by getting the damage attributes on each item object, but I posted it here since I figured this is more of a UCC problem.
 

Attachments

  • MainDamageProcessor.cs
    12.9 KB · Views: 7
If you want a reference to both the bullet and the gun in the processor you'll need to subclass the ShootableWeapon component. By default the processor only contains a reference to the shootable weapon if using hitscan or the projectile if using a projectile fire type.
 
Ah, that makes a lot of sense, actually. I can't believe I hadn't thought of that haha. Thank you!

Edit: Ok, so I'm trying to inherit ShootableWeapon for a custom shootable script, but it's looking like a lot of the variables I want to use are inaccessible. My initial thought was to override the ProjectileFire method, creating a reference on the spawned projectile's damage processor. It seems like this way won't work, though. I'm not a very experienced programmer, so I think I need a bit of advice here. Should I just duplicate the ShootableWeapon script, then make my changes?

Edit 2: Um, never mind haha. I just set the variable through a small custom script that I placed on the gun alongside ShootableWeapon. It just makes the gun's DamageProcessor reference the gun gameobject, which gets transferred to the bullet. It works pretty well right now. Thanks for the replies, though!
 
Last edited:
Top