Hit events are not generated all the time

I am experimenting with a fps like game in which you have a rifle and shoot a series of standing characters (all inherit from the unreal character class)

I’ve written a projectile blueprint class which contains a static mesh projectile.

The projectile has its Event Hit event implemented. Which basically deals damage to the hit actor (if it implements Damagable interface) and emits a particle system and a sound for the hit effect and destroys itself.

This works mostly. But some bullets (like 1 in every 10) are reflected (like mirror reflection) from the characters once they hit them. It seems like the physics engine is correctly detecting and handling the bullet hits but the Event Hit is not fired in the editor, so the bullet has no way of destroying itself or dealing damage.

So far I’ve tried:

  1. Set generate collision on hit for all bones (to which a collider is attached) in the PhAT of the in game characters
  2. Set generate hit events both for the bullet mesh (which is at the same time the root of the blueprint) and the characters’ skeletal mesh.
  3. Specified a new collision channel named “Bullet”. Set the collision preset of the projectile mesh to Custom and changed Object Type to “Bullet”. Set Collision enabled to physics only and set to block all channels.
  4. Set the capsule collider of the character to Custom preset. Preserved everything from the previous Pawn preset but set response to the Bullet channel to ignore. (I want the skeletal mesh to respond to bullets for locational damage).
  5. Changed Collision Preset of the skeletal mesh of the character to Custom. Again preserved everything but changed response to “Bullet” channel to block. Also changed collision enabled to “Collision enabled(Query and Physics”).

I am seriously stuck with this issue. Could you guys suggest me a way of fixing this?

Hi Matiati,

There are a number of things that could be happening here. First I’d like to narrow down the possibility of your assets being the cause rather than it being a bug with the engine. To do this we need to set up a simple test case.

To test this I followed these steps:

  1. Create a project using the first person shooter template and duplicate the skeletal mesh found in engine content so you may add it to your content folder. (adding any skeletal mesh will work really I would recommend the UE4 mannequin if you prefer)
  2. Create a default character BP and set the mannequin to the mesh component
  3. Change the collision settings on the capsule component so that it ignores projectiles
  4. Change the collision on the skeletal mesh component so that it blocks projectiles and generates hit events.
  5. Place the character BP in the default FPS template level
  6. In event graph for both character BP and Projectile BP add print sting node on event hit (make them different colors and the duration 999)
  7. Double check projectile collision component’s collision settings such that it is set to generate hit events and that it has block enabled for all things. (should be on but it’s good to check)

While testing I got a print string output to the screen every time I shot the character mesh. I did notice that you were using your mesh for collision on your projectile and not a collision component. Try using a collision component (sphere) instead and turn off collision on your mesh to see if that works a little better.

,

Ed

Hi Ed,

for your answer.

I am already using the default Mannequin character from the FPS template.

Up to step 6 we share the exact same setup. But yes I’ve used the mesh’s own collider (without a collision component) to get hit events. However I’ve tried your collision component option but unfortunately it didnt work as expected either.

To update the mesh using physical simulation, I have to let the skeletal mesh to respond the collisions otherwise the engine gives me an error.

I’ve tried to disable skeletal mesh from generating hit events (but still updated by physics). And tried both sphere and capsule collision components (both as root of the actor and child of the s.mesh within the actor). Capsule and sphere collision components resolved the issue but with high speed projectiles this time some of the hits are missed entirely (instead of getting reflected from surfaces they pass through). Enabling CCD also did not resolve the issue and I did not want to activate substepping for performance considerations.

Though I’ve found a better solution to my problem. Whenever I fire a ranged weapon I the PredictProjectilePath function from the Unreal library. I set Object types to WorldStatic only. This gives me an estimated trajectory of the bullet which considers only static actors. Then I assign the trajectory to a spline component I attached to the projectile actor.

At each Tick (tick times can be configured for performance) event of the projectile, I first accumulate the deltaTime parameter into a shootTime which was initiated to zero when the Shoot function was called. I then sample the next position on the spline at shootTime. And attempt to Move the projectile to the next position (and rotation) with a sweep. If the sweep returns a hit actor and a bone then I the takeDamage routine of my interface.

This approach effectively solves the high speed bullet collision problem and consistently captures all hit events. It is also configurable through setting the tick interval of the projectile. Basically more ticks = smoother projectile path, less ticks = less sweep querries.

I believe this is a good answer to this question. But I still believe that the missing hit events issue is a bug.

This may not be a bug, it very well could be a simple precision issue. This depends on the size and speed of the projectile vs what it is attempting to collide with of course.

If your projectile is moving very quickly and travels mostly straight it may be a good idea to use a ray trace as well and have the projectile there for visuals only.

Just so that I can reproduce your scenario would you mind sharing your projectile settings in a screenshot so that I may test and determine if this is a bug with the engine.

,

Sure…

Here are the collision presets for the my game character blueprint (inherits from unreal character) and my testProjectile blueprint.

“Bullet” is my custom object type for projectile.

The projectile’s event graph is as follows:

And OnHit function:

In this setup bullets hit %90 of the time but reflect from character meshes like %10 of the time.

Hi Matiati,

At this point I would determine this to be a precision issue. I put together a projectile system like the one you showed and with a high enough velocity caused the projectile to pass through the target. That is what you are reporting if I’m not mistaken.

I think it’s fine predicting the trajectory of the projectile however, I don’t think you need to map all the points to a spline and do all that collision checking on tick as you move the projectile along the spline. All you would need to do is run the predict projectile path function, make sure that all objects you want to account for collision are included in the object type list (for example check for the character mesh instead of world static).

It will then trace along the path stepping along the way checking for a hit. The accuracy depends on the sim frequency. You can also increase projectile radius to help fill gaps. It will return a hit in the form of a bool once this trace touches the desired object.

you can use this bool in a following branch node and if true fire a custom event (named hit event if you want). You can just have the actual projectile be visual since you are using the predict projectile path to check for hits.

That way you aren’t running the predict projectile path only to run a series of checks again when you move the projectile along the spline generated as this is twice the work. Oh and the sim frequency can be adjusted for performance.

I hope that helps,

Ed