Using a blueprint to set a variable on a spawned actor

Hi all,

I’m hoping that the answer to this is far simpler than I think it is but I’ve looked around on the various forums and threads and seen several different answers across the last 4 years.

So, here’s the situation.

I’m putting together an FPS game and I’m trying to avoid having lots of blueprints.
What I’d like to do is have a single blueprint for each weapon ammo type i.e. BP_Projectile, BP_Explosive etc.
The Weapon BP’s already set the rate of fire and clip sizes but currently the damage is stored in the Projectile.

I’d like to have it so that the Weapon also carries it’s damage information and when it fires “SpawnActor - Projectile Base” I want the Engine to tell the projectile what it’s damage is.

I’m hoping that this means when the ActorOverlaps the target, the Enemy_AI can get the damage information from the bullet that just hit it instead of having to attempt to cast to different weapons or to check which of several WeaponBP’s has just shot it.

I’ve tried writing functions and interfaces that set the “Damage” and having the target cast back to the ProjectileBP but it doesn’t seem to work. Also, when I try to Cast to the Projectile BP, I struggle to get an “Object” reference to attach to it.

Like I said, there seems to be a lot of conflicting advice but it’s split across several years and I can’t tell if there’s been a new addition recently that will be a magic cure all function for this kind of thing.

Many thanks in advance.

so if i understand correctly you have many projectiles and you want the gun to tell the projectile how much damage it should do by setting a variable.

if thats the case then theres one way i can think to do it and thats by having all your projectiles inherit from a base projectile class which contains the damage variable. so you will need to create a projectile class then for each projectile type create a child of the base projectile class, so explosive and incendiary rounds would be a child of the base class and both would inherit the damage variable. then in your gun where you spawn your projectile you could then drag off the blue return pin (which is a reference to the spawned actor) and cast to the base projectile, then you set the damage there. the cast will work since all projectiles inherit from the base class and all have the damage variable.

theres also the expose on spawn but i dont think its applicable in this case.

Hi ,

Just ran it through a quick test and yes, it literally was that easy.

I feel like the guy trying to cross a river and thinking he needs to build a raft and you’ve come along and pointed out that there is a bridge just around the corner.

No idea why my initial attempts to cast to my base_projectile didn’t work but this little set-up works absolutely fine.

Thank you for a quick and accurate answer!