How to replicate UProjectileMovementComponent::bRotationFollowsVelocity?

Hello :slight_smile:

Got a little problem here with shooting arrows in a dedicated server environment.

Everything works fine so far, except the only thing that “UProjectileMovementComponent::bRotationFollowsVelocity” doesn’t seem to be replicated or something like this and I can’t figure out what I’m doing wrong.

I tested it in Single Player just see if it is a replication issue. And it seems to be? In Single Player the arrow’s rotation follows its velocity, as it should. However in Multi Player the arrow follows the ballistic arc, but points straight down the moment it gets spawned and doesn’t change anymore.

Single Player:

Multi Player:

Spawning the arrow (Server, Reliable):



FActorSpawnParameters SpawnInfo;

SpawnInfo.Owner = GetOwner();
SpawnInfo.Instigator = GetOwner()->Instigator;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

FVector Location = Character->GetActorLocation();
FRotator Rotation = Character->GetBaseAimRotation();

ADefaultArrowProjectile* Arrow = GetWorld()->SpawnActor<ADefaultArrowProjectile>( Arrows->ItemClass, Location, Rotation, SpawnInfo );
if ( Arrow )
{
	Arrow->GetMovementComponent()->Velocity *= 3000.f;
	FVector Velocity = Arrow->GetMovementComponent()->Velocity;
	UE_LOG( LogTemp, Warning, TEXT( "Arrow spawned! %f | %f | %f" ), Velocity.X, Velocity.Y, Velocity.Z );
}
else
{
	UE_LOG( LogTemp, Warning, TEXT( "Cannot spawn Arrow!" ) );
}


Arrow class (ABaseProjectile → ADefaultArrowProjectile):



ABaseProjectile::ABaseProjectile()
{
	bReplicates = true;
	bReplicateMovement = true;
	PrimaryActorTick.bCanEverTick = true;

	// ...

	MovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>( TEXT( "MovementComponent" ) );
	MovementComponent->UpdatedComponent = CollisionSphere;
	MovementComponent->InitialSpeed = 0.f;
	MovementComponent->MaxSpeed = 0.f;
	MovementComponent->bRotationFollowsVelocity = true;
}


Whats wrong here? :confused:

Hmmm … thats strange. Just tested if it changes anything if I set the “MovementComponent->InitialSpeed” and “MovementComponent->MaxSpeed” to a fixed value and removed adding velocity after spawning. And it does indeed?!

But thats not how it is supposed to be, is it?



ABaseProjectile::ABaseProjectile()
{
	// ...
	MovementComponent->InitialSpeed = 3000.f;
	MovementComponent->MaxSpeed = 3000.f;
	MovementComponent->bRotationFollowsVelocity = true;
}

ADefaultArrowProjectile* Arrow = GetWorld()->SpawnActor<ADefaultArrowProjectile>( Arrows->ItemClass, Location, Rotation, SpawnInfo );
if ( Arrow )
{
	//Arrow->GetMovementComponent()->Velocity *= 3000.f;
}


Yeah that looks right. Double-check in ShooterGame, their projectile class uses this.

I don’t have “ShooterGame”. Do you mean this? http://shootertutorial.com/ If yes, then I can’t find any source code to download. However, there is a tutorials site where he talks about creating “Grenade Launcher”. But he is also using fixed InitialSpeed and MaxSpeed … Create Grenade Launcher | Shooter Tutorial

Or this Generic Shooter in Blueprints - UE Marketplace ? Not going to buy. :wink:

Or the “First Person Template”? This is also using fixed Speed.

Found another one: GitHub - var-ivaylo/Pacboy: Multiplayer third person shooter game made in UE4 for my final year in school … But also using fixed speed.

Anyone? This behaviour is also reproducable in a blank new Blueprint project.

The problem is:

Setting projectile velocity in combination with “Rotation Follows Velocity” after spawning only works for single player / server, but does not get replicated to the client(s).
Instead clients see the projectile following the correct ballistic arc, but always nose down.

fb23c4c0498d3bcc91db422eecb790a93c782c5f.jpeg

“ThirdPersonCharacter” Blueprint and “Arrow” Blueprint are both set to Replicate and Replicate Movement.
“Arrow ProjectileMovement” Component is set to “Rotation Follows Velocity”

Whats wrong here? Is this a bug in UE4?

ShooterGame is a free Unreal Engine sample in the Learn tab of the Launcher, it’s free.

Ah, there it is. Thank you! :slight_smile: … Downloading.

Repost your issue in AnswerHub;
If you’re sure this is an engine issue, post in bug report section, Epic staff answer faster in there.

Ok, I had a look. Put in a StaticMesh for the “ProjRocket” projectile to show an arrow and there it works indeed, even in Multiplayer and with Initial / Max Speed = 0. Need to take a closer look then. Thats a great learning source. :slight_smile: