I have been playing around with replication in Blueprints and have come across something I don’t understand. When I try to call a “Call From Server” event from the client, it doesn’t seem to be doing anything.
The Server function has an Authority Switch, looking for the Authority. The client portion (from an input event) is not checking for Authority or Remote and after collecting the desired variable data from the client side, calls the Server function. If I run on a “server” client (no dedicated server), only the host client can call the function (and have it work). If I work with dedicated, nothing happens on either window – I run two to test.
The Spawned Actor is a “custom” projectile that is being replicated (for both normal replication and movement). - again, this works if called from a host client, marked as “server”.
your ServerSpawnProjectile is using properties(Projectile Class, ProjSocketTransformation) from other event’s result, which is bad as you don’t know for sure if they set properly even thought it should only run on the server side pawn and then replicated to client.
What you need to do at least is make your server spawn event have these 2 input vars, and pass it over.
So I made the Server function take in the three parameters for the Projectile Class, the Projectile Transform (spawn location and rotation) and then the Projectile Velocity. It still has the same issue. It works when fired from the host client but a remote client doesn’t fire at all.
The parameters being passed in are coming from the first image on the first post, directly from the function called on Left Mouse Button.
can I assume the content of spawn projectile is roughly the same?
Then the next step would be trying to determine if that’s cause by collision.
When I did my projectile a while ago, I have to offset the transform a lot so my projectile won’t hit pawn itself when spawned.
Maybe you have similar situation, assume you assign something wrong for the projectile to ignore, but didn’t account for server/client situation,
you would actually have one side fire properly, but the other side hit when projectile spawned.
I later fixed it by letting collision shape to get the instigator without any authority check.
(I don’t know why your SpawnActor node doesn’t have a instigator pin exposed, I have that on all the spawn node.)
Actually spamming authority check is pretty bad, I had to remove quite a few when cleaning up my blueprint after implement projectile and damage.
So maybe you can try make your projectile to overlap or ignore all, and see if it fires properly.
I tried both having the SpawnActor set to “Spawn Even If Colliding” as well as removing all collision from the projectile itself. It is as if the Server event isn’t being called at all, when executed from a remote role.
Furthermore, I can tell that if called from a Server function, the projectile will replicate properly (for both remote and authority roles) if fired from a authority client. If fired from a remote client, nothing happens.
I’m at a bit of a loss. I’ll keep fiddling with all this but I really can’t make sense of it.
stay that way but have one authority check after your ServerSpawnProjectile(actually this don’t need to be reliable, I tested the difference, it’s pretty safe)
Stick with the no collision first for projectile bp.
remember that the pawn you see at client side has a counter part on server.
when you use authority check, it is to check which pawn that received event is going to run the rest graph.
I’d say remove other things first(just break original tree link in) and just maybe spawn a cube on origin or in front of your pawn.
here is my actual blueprint to fire projectile, I don’t have different type of projectile yet, so I just select the class manually.
If I remove the Trace I use to make sure the projectile velocity is set to the location I am aiming ( spawning it and letting the projectile take the normal velocity path it would based on its initial speed / spawn location) it works on both authority and remote clients -no authority check on either.
The issue now is that is appears the Server event wont change the Velocity of the ProjectileMovementComponent. - The cast exists (not null) as well as the Velocity from the Suggest Projectile Velocity function. I can base this on if I change the initial speed of the Projectile to 0 and the velocity to 0,0,0, the Projectile will spawn but fall directly to the ground (even though the SetVelocity function is being called)
make sense now why it’s not working, as the parameter you saved( velocity and transform) is not replicated.
ie on client side, you set the variable properly, on server side, you fetch the parameter that aren’t replicated(which is still default).
But in later case, where you pass information as event parameters, should work properly.
I’ll test and see if I can get some base rules right, as mentioned in another thread, so I can write a new wiki about replication.
In the mean time, when you call the rpc, do a print for both the value you passed in, and print after the rpc received the event(after a authority check to make sure it’s on server).
It should help you understand where the discrepancy happened.
So I ended up foregoing all “Projectile” related components and setup a Actor with a Collision Sphere and Physics Handle. I spawn it and set velocity exactly as with the Projectile but instead of “Set Velocity”, I am using “Set Physics Linear Velocity”. Also, to simulate gravity, I have this in the Actor Event Graph:
So with the same kind of variables, I can set the Actors velocity through space as well as the amount it falls per tick. Seems to be working just fine
It is a Server function - why would any other client need replicated variables if everything is being done on the server?
It is my understanding that replicated variables are needed when other clients want to use them for something but the server has a “copy” of all the clients, so when a Server function is called, it calls it from the copy - not replicated to other clients and then called there.
I am currently doing a “upgrade version” of the Content Example’s Network_Features level, so hopefully I can release the updated levels in a small package with a wiki explain what happens.
First question, if everything is done on server, it is fine “if” all clients needed are replicated actors and it’s movement component, if your client needs anything from a variable to show changes(say health in hud), then the variable need to be replicated.
Second question, from my test(with 4.4.2), server has a copy of every client, same for all clients. The only thing that replicated automatically are actor(the container) and it’s movement component when you check those in default tab.
When you call a function, you have to specify which copy actually issues the call by authority check, and depending on the event type( multicast/run on server/run on client), you would have different result if your graph does not consider the consequence.
I did a example in the test room 1.5 where there is a random variable delayed after the multicast event are called, it was meant for cosmetic function, so it runs on both server and all clients, as a result, even with authority check, server and client will get independent random variable.
I have to later move the random number delay to before calling the RPC to make sure the off sync behavior is correctly reflected when you don’t do a authority check.
It depends heavily if you want to use a certain variable in client side or not, and even the event type will affect your result.
So right now I can only suggest you that proper way to call anything to run on server, for projectile case is like this.
make sure you have a authority check before you call your run on server RPC
in your run on server RPC, make sure you won’t later have a event that depends on some variable that’s been set only on server.(for example your EventTick to update velocity)
just set it and let the physics and ProjectileMovement component do their replication. actually you probably don’t need any update like that, my projectile component did not have any of those except a timeline to destory actor after begin play and event hit to call a pawn interface function.
but if you want to do a homing missile, it would be different approach for sure.( I probably need to carefully redo my projectile after finish the upgraded Network_Features level. )
EDIT: Scratch 1., it depends on what you wanna do, I modify my pawn and can’t get client to fire again.