Download

UProjectileMovementComponent - controlling when velocity is added

I’ve got an actor object which is sort of a “pickup”, lets say a baseball. You can see it in the world, walk over and grab it. Once your character is holding the object, you can throw it which will of course give the object a velocity and a direction. I’d like to use the UProjectileMovementComponent component for this purpose, as it supports useful behaviors like homing and bouncing after impact. I don’t want the projectile behavior until the object is thrown, but the object exists as you’re holding it in your hand.

If I give the actor a UProjectileMovementComponent during creation, it will instantly move like a projectile (beginning at InitialSpeed). I haven’t had any luck modifying the velocity after creation. Finally, adding a UProjectileMovementComponent to an actor after it’s already been initialized doesn’t seem to work, the object doesn’t move anywhere. Perhaps I haven’t been adding the component correctly post-creation, or I’ve missed another way to create a UProjectileMovementComponent with velocity anytimo other than on creation?

For the moment, my solution has been to have two almost duplicate objects. One without the UProjectileMovementComponent, and then when the object is thrown I delete that object and immediately spawn an almost duplicate object but with a UProjectileMovementComponent. It seems very hacky, hoping there’s a cleaner way.