Blueprint Casting Works fine with one set, but doesn't at all with a second

Hello, I am have set up an FPS Template game, I have a problem, one of my power ups is casting just fine, I go over it, pick it up and it casts to character blueprint and changes settings.

how ever, when I pick up other power up, settings that need changing are in projectile blueprint, so when I replicate exact same method of casting but between these too blueprints instead, (2nd power up and projectile) cast fails.

Im assuming that I cant cast projectile blueprint, is there anyway around this?

so just to clarify; 1st power up - Cast to myCharacter BP = Works, 2nd power up - cast to myProjectile BP = Doesn’t work.

Here is a screen shot of BP script. and working one is near enough exactly same. just to a different BP


Thanks in advance for anyone willing to help! :slight_smile:

Hi Virtuosic Kitty,

If I read this correctly, it looks like you’re OnComponentBeginOverlap is returning Actor that collides with it. If that Actor is your character, Object input in Cast To MyProjectile can’t do anything with it so cast fails.

A better way to do this is to cast to Character and affect a variable, then feed that variable into function that spawns projectile. Once projectile is spawned, take output and set Explosive Active from there. You may run into some problems with turning it off this way, and a more modular method would be to call a function inside projectile blueprint that sets, delays, and resets Explosive Active bool.

Hope that helps!

This sounds like exact method i need, how would one go about feeding that variable information to another blueprint?

Thanks in advance.

Well, here’s an easy way to do it, if not most efficient:

In your Projectile Blueprint, create a Custom Event for variable you’re setting, very similar to what you were previously doing in Pickup Blueprint.

In your character Blueprint, declare a bool variable for whether Explosive Ammo has been activated, default False. Do a quick branch to see whether it’s True, and if it is, call Custom Event in Projectile BP. Spawn Actor From Class will give you a direct link to your projectile, so you don’t need to do an explicit cast first.

Then in your Pickup BP, this is what your OnBeginOverlap will look like. In this setup, you’re casting to Character to set ExplosiveAmmo bool.

There are certainly better ways to handle this. For example, I would recommend creating a parent Projectile class and then creating children of that for each type of projectile you intend to use. Then you can determine which type of ammo is active within Character BP, and simply spawn correct type without ever needing to adjust anything in base Projectile BP. That’s a bit more complicated, though, and I just wanted to get you started.

Hope that helps!

Here’s some documentation on Parent/Child Blueprints, if you’re interested in learning more:

https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/Blueprints_Advanced/2_5/index.html

Thank you very much! Worked a treat, cant get a lot of stuff working now! :slight_smile: appreciate help cheers!