Hello been searching around but been unable to find any info on replicating projectile.
Right now i have a projectile thats setup with a collision sphere, a mesh, particle and a UProjectileMovementComponent.
In my weapon class i have a subclass of my projectile class.
Witch i spawn with a RPC call
UFUNCTION(Reliable, Server, WithValidation)
Everything is working as intended but if fired on one client no projectile is shown on the second one.
So am wondering if anyone have some resources on how to do this for Multiplayer?
I have found some stuff on the Wiki but as far as i can see, its not covering multiplayer.
I assume you mean UFUNCTION not UPROPERTY and the projectile already spawns on the server? In that case, add bNetLoadOnClient = true; in your projectile’s constructor and it will be instanced on clients. Also make sure the projectile only gets spawned on the server and never on a client, otherwise you might end up with two projectiles on the instigator client.
I recently ported the blueprints networking tutorial to C++ as an exercise to learn this stuff. So with that in mind the following may be completely incorrect! I’m still hoping good written documentation.
Basically if I’m the client, I call the RPC ServerAttemptSpawnBomb() otherwise the implementation (server) version. I’m not sure from your post if this is what you’re doing.
I also set any replicates flags in blueprints for my projectile even if I’ve done it in code.
@: I wouldn’t recommend spawning a projectile (or bomb) on the client itself. The server will spawn a projectile independently which gets replicated back to all clients and the original client ends up with two projectiles instead of one.
Granted, it’s a bit cumbersome to always write two functions, but I think it is pretty clean and you do not need to call the _Implementation function manually. You can also make the RPC call private or protected and only expose the client side function to hide the server call.
No, in UE4 the server is authoritive and only its world is the valid one. All clients only try to simulate what is happening on the server as best as they can. Exceptions are only made for certain actors (e.g. the local pawn and controller) and the only way they have to get the server to change something is by using RPCs.
Server functions only go one way from calling client to server, **Client ** functions only go one way from server to the owning client of an actor and there are also **NetMulticast ** RPCs which go from the server to all clients. For everything else there is property replication.
If you want special things to happen once a property changes you can use ReplicatedUsing=FunctionCallback to call FunctionCallback everytime the property changes. Furthermore you can add one parameter to the callback function with the same type the replicated property has. The parameter will then always have the pre-replication value of your property.
You might want to take a look at this: http://udn.epicgames.com/Three/ReplicationHome.html
Granted, it is for UDK and UnrealScript but the concepts are basically the same in UE4 and the documentation is pretty complete (contrary to UE4’s at this time )
Replication callbacks will only be called on clients and only if the value they get replicated from the server differs from their local value.
For example the UT3 Weapon system had a counter that got increased with every shot and clients would play shot effects whenever it changed. It worked like this:
The owner client shot the weapon, increased the counter, played the effects and called the server shoot function. The server then increased the counter on its side the same way and played the effects as well (if it wasn’t dedicated). After that the server replicated the new counter value to all clients. All clients except the owner client now executed the replication callback function to play the weapon effects on their side. The reason the owner client does not is because its counter value already matches the new value replicated by the server.
I haven’t actually analyzed the Shooter Game of UE4, but my guess is that it works somewhat similar at least. Apart from that, the method described above still works, I use it for my weapon replication. I hope that clarifies how ReplicateUsing works.
Has anyone encountered issues with choppy replicated projectiles? I believe I’m replicating my projectiles correctly (spawning them on the server with authority, apply velocity on the server, net load on client, replicate movement), but they appear choppy in-game, so I’m doing something wrong but it’s yet unclear to me.
I’ve encountered this issue, particularly with fast-moving projectiles. I’m thinking of a new way - replicate the projectile, and replicate its position (only initially, so clients have a start position), and firing velocity, so clients can move the projectiles at said velocity. Turn off collision for the bullets on client as well, so there’s less CPU load. Definitely not as good as having 0 computation for bullets, but it’s better than choppy bullets.
I like that idea. I like it so much that I implemented it, and I think it works pretty well. I didn’t implement any rewind/replay, but since the ProjectileMovement components are so predictable I haven’t noticed any deviations (yet).