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;
		Bowl();		
	}
}

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:

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.

any progress on this im having a similar issue

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

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

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

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!