How can I replicate a Projectile Movement Component's Initial Speed before spawning a replicated projectile?

My setup is as follows:

  1. A client locally selects velocity and calls a server function with the velocity value as one of the parameters;
  2. The server spawns the replicated projectile. What I’m trying to do is use SpawnActorDeferred(), then set the Initial Speed of the Projectile Movement Component, then FinishSpawning();

The Projectile Movement Component is set to be replicated as well; but the result is, the server projectile flies with the set speed, but the client projectile flies with the default speed that was set manually in the projectile blueprint.

So what should I do to have the projectile have the same initial speed across all the players?

Thank you!

Hi.

Most simple way:

Client → Server → Multicast.

Or create replicated instance editable velocity variable inside projectile, and set Movment velocity in construction using this variable.

Haven’t tried doing it in construction, I’ll check that and report back.
Thank you!

Unfortunately, this doesn’t work either. Multicast function on clients is fired after the projectile starts moving.

Have you tried setting Replicate Movment to true?

Yes, but with it there’s a conflict between the server speed and the client speed and the projectiles start lagging like crazy.

On both sides or only on client side?

On client, because the client velocity is different from the server velocity, and it tries to fly faster, but the replicated location pulls it back every replication tick.

Here you go.
I made it in BP, you just do the same in C++.
Looks like variable can’t replicate On Construct, too fast.
But can on begin play.

Projectile Class defaults:
Forum5

No need to replicate Projectile movement component.

Projectile Begin play and Vel variable:

Spawn from character:

Red part is needed speed.

3 Likes