If Projectile is overlapping actor when spawned, it will 10 Damage?

Hello,

I have a projectile class setup, where if a projectile overlaps with a damageable character class, then it will deal damage to that character, the problem that I am having, is that when the projectile spawn point is already overlapping with a damageable character, then it will always deal 10 damage per projectile.

The trail of damage starts in the Shoot function of my weapon class, which will send the damage and range of the weapon to the projectile.(The Default Damage is set to 1)

The set Damage/Range Function will initialize the variables in the projectiles class preparing it for the on-overlap event.(Default Damage is set to 0)

The overlap event will cast to damageable characters in my game and apply damage to those characters.

1 Like

Hey @LT49SWEGGER! Welcome to the forums!

So all of this stuff is great! Problem is… it doesn’t cover where I’d start with questions. So firstly: Where are you setting the damage variable?

Secondly, does the projectile do less damage the further away it is? What causes variance in damage?

Thirdly, is ten the most it could do? You said the minimum is 1.

We just need some more information, and I’m sure we can get this squared away post-haste! :slight_smile:

1 Like

Hey @Mind-Brain Thanks For Helping me out with this.

As of right now, Damage in my weapon class is being set in the class defaults panel so when making a weapon you can tweak the variable whenever you want. I checked the weapon blueprint and saw that there were no other instances of me setting the damage variable.

as for your second question, damage is never supposed to vary. It is set in the class defaults panel of the weapons class and is passed to the projectiles from there. It works perfectly fine when the projectile spawn location is not overlapping a damageable enemy.

third question, as of right now I have 4 different weapons of varying damages they all work until the projectile spawn point overlaps with the damageable class then they all will always do 10 damage.

Okay, so follow up question!

How does your collision code work? Are you making sure to only allow the projectile to damage each enemy one time? Is it doing 10 damage one time- or one damage 10 times? Use printstrings to find out! :slight_smile:

1 Like

It did some print strings on the event begin overlap event. It is doing 10 damage 1 time

So is the projectile damaging the character who fires the weapon then destroying itself?

If that’s the problem, add a branch before casting to bp_ damagable. and check if OtherActor from the overlap event = Instigator. If it’s not, move on to the cast and stuff. Also, in the function which spawns the projectile, plug a reference to the charcter who owns the weapon into the instigator pin on the Spawn Actor node so that check will work.

1 Like

Okay, I figured out what was causing the 10 damage, I was using a child class “Bullets” that spawned from the weapons, The damage variable was set to private in the parent class, so I couldn’t see it in the bullets class.

The question still remains, Why is the damage passed from the weapon not being applied to a projectile when it spawns inside another entity of the Damageable Class?

Feel free to hop in and help, but I have a feeling I’ll figure it out soon. I’ll post the answer as soon as I do.

This has something to do with Overlap Event firing before set damage does. Therefore causing damage to not be applied to the projectile. I’m going to try again in the morning:')

If I’m understanding your issue correctly, a quick easy way to solve it would be to add a branch check before setting up the damage logic so it has time to get away from the character before activating. Create a Boolean variable such as “IsActive?” make it false by default. On event begin play put a very small delay and then set it to true. On your overlap event just branch check IsActive? True-> cast False-> nothing. The delay is just long enough to clear your character.

1 Like

So it’s an issue of code order!

So what you’ll want to do- instead of using this:

image

Put the damage and range code on the projectile! On begin play. So it runs as part of the initialization of the bullet- Begin play has to finish before any other code is run iirc, so it should always run that before the overlap code. :smiley:

1 Like

Okay I Figured it out. Thank you, guys, so much for helping me think through the problem I really appreciate it.

For my issue the overlap event was firing before the set damage event, So I set my default “Generate overlap events” to false for the projectile,

Generate overlap events

and in my set damage/range function I set “generate overlap events” to true. So, my projectile can’t overlap with anything until the damage is set. therefore, preventing it from dealing damage with a default value. This fix works perfectly for what I needed.

^^^^^^^^^^ above is answer, below is what I tried and didn’t work.

I tried using a user bool in the set Damage/Range and a branch at the begin overlap event with a retriggerable delay that retriggered until the damage was set but that just tossed an error saying that “Take Damage” Function was not retrieving any values.

I also tried working with event begin play, but I wouldn’t be able to get a reference to the weapon that was shooting it, I needed the weapons to be able to determine the damage and range values of the projectiles, so I can easily tweak balancing issues.

Thanks again for your help guys!
-LT

EDIT

Okay, so I just found a much better way of going about this.

Expose on spawn the variables that you want to construct with the bullet, whenever you want to spawn a bullet, the spawn node will have the exposed variables as pins so you’ll be able to construct the bullet from there.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.