Casting to projectile fails

I have re-edited my question to be more clear.
I have 3 Blueprints which are important now:

  1. Bullet - It’s the actual projectile
  2. RotationCharacter - my Character blueprint
  3. TEST_Projectile_Pickup - it’s the pickup blueprint

1 This is the projectile where I have a static mesh and a projectile movement component and as it is shown, it’s initial speed is set. In it’s Event graph, there are only damage related things.

2 This is a Fire projectile function inside my Character blueprint. This is the actual part where I shoot the projectiles.

3 And this is the Pickup blueprint which has only a static mesh component. This is the Event Graph.

So my question is:
How to change Initial Speed of projectiles (Bullet) fired by the character (RotationCharacter) when the character overlaps the Pickup mesh?(After the player picked up the Pickup) The player character triggers the OnComponentBeginOverlap, but the CAST to the bullet, always fails.

Btw, using UE 4.5

I still haven’t figured out how to do this. Some from Epic can help me?

Can you edit the question with a few more images? Also try to explain the problem more clearly.

In the title you say You are trying to cast to Projectile, however in the description you say you want to cast to Character but fails.

Also what do you want to achieve here?
a) Change projectile velocity when it overlaps with the Pickup volume?

or

b) Change velocity of projectiles fired by the character when the character enters the pickup volume?

I have rewritten the whole question, I hope this time it’s more clear than before. Thank you for taking time to help

Ok, I am assuming two things:

  1. Once the character overlaps with the pickup, any new projectiles fired will get speed boost. Those that are already fired are not affected.
  2. Once character picks-up the pickup, its effects are active even after character gets out of the volume. The effects are active for N seconds.

This is how I would do this (of course there are many possible solutions):

You will need this variable inside your character:

  • float ProjectileBoost (default 1.0)

When you have overlapped with the pickup volume, cast the Actor to your Character class and set the value of ProjectileBoost to something greater than 1.0.

In your Projectile class, you will need an additional variable

  • float BaseVelocity (default whatever you like)
  • float BoostFactor (default 1.0) - check ‘Expose To Spawn’.

Then in the construction script of projectile set ProjectileMovementcomp.InitialVelocity = BaseVelocity * BoostFactor. In the Fire event of character, spawn a projectile and connect ProjectileBoost to BoostFactor(on spawn node)

EDIT: Updated answer.

Okay, so I tried both versions and it’s still not working. First I tried changing it from the character’s fire event after the projectile has been spawned. It did not work. I tried the other solution too, that also did not work. I was thinking I have some problems with my project, so I created the First person shooter template, made a pickup actor from scratch and tried to cast to the projectile but it didn’t work. So it wasn’t my project’s fault. So I tried in UE4.4… It did not work there either… I’m so desperate for finding a solution for this… I cannot proceed further with my game’s development if I don’t make this work… Any other ideas why this isn’t working?

Sorry to hear that it did not work for you. But I am quite sure that you are missing something very simple. so lets try to find the problem.

NOTE: i made a small mistake. In method 2, you must set InitialVelocity in ConstructionScript of your projectile NOT BeginPlay as I posted. Addionally you must create a second float variable in Projectile (apart from BaseVelocity) called ‘BoostFactor’ (float) and check ‘Expose To Spawn’. Then in the construction script set InitialVelocity = baseVelocity * BoostFactor. In the Fire event of character, spawn a projectile and connect ProjectileBoost to BoostFactor(on spawn node)

If its still not working,

First you must make sure all the casts are working. To do this add a print string node to every ‘Cast Failed’ pins. Then run the game and see if any of these print strings are actually triggered. If it is, then you must first resolved this.

If that is not the issue, then the next step is to see if all the variables are updatedd correctly. Again use print string to print out values of Basevelocity, ProjectileBoost etc from Fire event. once you spawn the projectile we must check what the value of inital velocity is; so print that out after you have spawned the projectile.

You can also use Debugger to quickly find where things are going wrong.

Wow, it worked! Okay, so what I learned from this is when I cannot access a value from another actor, I should create a substitute variable for it like here. Working GREAT! Thank you so much!!! Please edit your answer and add the other information you posted in the comment, so others can see it clearly if they have the same problem :slight_smile: Have a wonderful day!