Download

[4.9.2] UProjectileMovementComponent Velocity changes do not move the projectile?

Setting the Velocity of my actor’s UProjectileMovementComponent does not cause the actor to move.
After some looking around on AnswerHUB, I checked UProjectileMovementComponent’s UpdatedComponent to ensure it was mobile and not static.
UProjectileMovementComponent’s Auto Activate bool is also set to true.

I am setting the UProjectileMovementComponent’s values like so:



void AProjectile::HandleVelocityChange(FVector InDirection, float Speed)
{
...
	ProjectileMovement->ProjectileGravityScale = 0.0F;
	ProjectileMovement->MaxSpeed = Speed;
	ProjectileMovement->InitialSpeed = Speed;
	ProjectileMovement->Velocity = InDirection * Speed;
...
}


HandleVelocityChange() is called immediately after the projectile is spawned by the Actor that spawned the projectile.

What is required to get UProjectileMovementComponent to work?

This is what I do:



void ABZGame_Ordnance::InitVelocity(FVector& ShootDirection)
{
	if (MovementComp)
	{
		// Velocity Imparted from Owner
		const FVector ImpartedVel = Instigator ? Instigator->GetVelocity() * InstigatorVelocityPct : FVector::ZeroVector;

		MovementComp->Velocity = (ShootDirection * MovementComp->InitialSpeed) + ImpartedVel;
		MovementComp->UpdateComponentVelocity();
	}
}


MovementComp is a ProjectileMovementComponent.

Thank you. UpdateComponentVelocity() is getting me some movement now, tho only on the CLIENT and only for some of the projectiles.
They also are effected by gravity despite ProjectileGravityScale being set to 0.0F…
Does UProjectileMovementComponent not replicate ProjectileGravityScale?

EDIT:
I got full movement now. Just needed to rework how it was being replicated.
Thanks again for the help.

No it doesn’t, that gravity property should be set as a default property and not changed.

If you want to replicate it, you’ll have to create your own replicated variable or change UProjectileMovementComponent and mark it as a replicated property. However, changing that property at runtime will inevitably result in a lot of synchronization errors, so client projectiles will jitter a lot. You want the client to simulate the Server as best as possible.