Projectile Collision Switch with ENUM

Hi I have two projectile BPs at the moment (player and enemy) but there will be more as the player acquires new weapons as well as more enemy types.

Now I have a collision issue:

The general youtube tutorial from UE4 does not work for me because the whole “get forward vector * 500” to spawn the projectile far outside the player so it doesn’t collide design looks like garbage plus for design reasons I want the projectile to spawn in the player / enemy.

This led me to using Overlap Events rather than hit so that the player doesn’t get stopped mid air when he shoots.

I also checked “generates overlap event” on all the static meshes in my level.

Now the BP gets really ugly when I try to work out the collision handling.

These are the types that e.g. the player bullet can collide with:

  1. The character: Always an overlap event on spawn since it spawns in the character → desired result: do nothing
  2. Another Player Bullet: Depending on character movement this happens sometimes → desired result: do nothing
  3. Enemy Bullet: Well two people shooting each other that happens sometimes, I just want to play some particle effect while they cross and stop it when they are done crossing and go on their respective ways.
  4. Enemy: Overlap event: Apply damage, play effect, destroy actor

Now is there some way I can make an enum with all the types of things it can collide with? Because right now I am doing something ugly and something not scalable to mutliple different bullet types:

The player bullet has a OnComponentBeginOverlap Event that I sequentially cast into “myCharacter” and if that cast fails than cast into “player-bullet” and if that fails cast into “enemy-bulley” (success = play effect), if that fails cast into “enemy”. On success apply damage, play effect, destroy, and on fail, by process of elimination it has to be a piece of level geometry and it should just destroy the actor.

As you can see that is bloated and if I add another type of projectile I have to throw another cast in there and of course replicate these cast chains in all other types of bullets with small alterations.

Is there a better way to handle this like with an enum which I can switch on (or any other technique for that matter)???

Thanks guys!

I found the way to do it. For anyone else wondering, here is how it works:

Go to Project Settings and Engine -> Collision and create a custom collision channel called “Player Projectile”. Then in the collision settings for the collider in the bullet BP, you can set the collision preset to custom and check ignore for everything except for the things you want to generate events with.

For example I made another channel for Enemy and EnemyProjectile and then set the bullet collision to ignore all except for enemy (Block, so it makes a HIT event), enemyProjectile (overlap so I can play some particle effects during the overlap) and worldStatic -> block. This way in the OnHit event I can simply cast to enemy and if that fails it has to be a worldStatic and the Overlap Event only fires if it hits another enemy projectile. It by default ignores spawining in my character or overlapping/hitting my other projectiles!