Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Projectile Movement Initial Speed won't use a Variable from the Player Character

I have a player character which picks up a bowling ball and then is supposed to throw the ball. I tried to set the ball to use a projectile movement component that would use the power variable from the Player Character, but it never works.

Bowler Character getting power and spawning the ball:

 void ABowler::OnBeginPress()
     if (bHasBall)
         BeginTime = FApp::GetCurrentTime();
 void ABowler::OnEndPress()
     if (bHasBall)
         EndTime = FApp::GetCurrentTime();
         float total = EndTime - BeginTime;
         Power = total * 500;

 void ABowler::Bowl()
     bHasBall = false;
     UWorld* const World = GetWorld();
     if (World)

 //Set Spawnlocation, rotation, and parameters here...

         ABowlingBall* const SpawnedBall =World->SpawnActor<ABowlingBall> (BallClass, SpawnLocation, SpawnRotation, SpawnParams);

Constructor for the BowlingBall which is spawned:

     const UWorld* World = GetWorld();
     if (World)
         ABowler* MyCharacter = Cast<ABowler>(UGameplayStatics::GetPlayerPawn(this, 0));
         if (MyCharacter)
             BallPower = MyCharacter->Power;
     ProjectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComp"));
     ProjectileMovement->InitialSpeed = BallPower;

     //Other Projectile Movement Properties...

Ball Power does have a value as you can see here: alt text

But, when the ball spawns, it just drops to the ground like the initial speed is 0. When I set it to a specific number, like 1000, it works fine.

Thanks, Martin.

Product Version: Not Selected
ballpower.png (65.0 kB)
more ▼

asked Aug 02 '14 at 05:07 AM in C++ Programming

avatar image

26 3 5 12

avatar image BPANDREW Jan 12 '15 at 01:36 PM

any progress on this im having a similar issue

avatar image formatt Mar 12 '15 at 11:18 AM

I am having the same issue. I guess i'm going to have to set a velocity manually instead. Any more information about this?

avatar image Venros May 30 '15 at 04:09 AM

I'm having the same problem, anyone figure out what was wrong yet?

avatar image CleanCut Jul 16 '15 at 05:48 AM

Not working for me either, when setting it in a blueprint.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hello, Vilepig

Please note that GetWorld() in this situation returns null since the World is not fully initialized when the function is called. This happens because GetWorld() is placed inside of the constructor.

In this situation MyCharacter never gets initialized and BallPower variable isn't set appropriately.

Thus, please place make sure that World has been initialized before calling the method that contains GetWorld() function.

Hope this helped!

Good luck!

more ▼

answered Jul 16 '15 at 10:45 PM

avatar image

Andrii Melnyk
1.8k 60 19 112

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question