Why my bullet and hit effect is not replicating?

For some reason it’s not replicating.

I have tried different combinations. To multicast, run on server, with and without reliable.

Anyone? #Cry

Network replication is one tricky beast!

Where is the bullet fired from?
As in, do you perform an RPC from your client, to the server, to trigger firing the weapon?

If you’re only firing from the client, then the hit event might only ever be local.

First, if your Bullet actor is Replicated, you don’t need a Multicast to make it exist on all machines, you just need to Spawn it on the Server.

Even if you multicast, if you do it from the Client it will not replicate the spawn to the server (in my experience). Multicasts go from server to client. If you do a multicast from a client, then the client only sends the multicast to itself.

To go from Client to other clients, you have to do a Server RPC, which then does a multicast to the other clients. Clients can not tell other clients what to do, only the server can.

But like I said, you might not even need to multicast, just set Bullet actor BP to Replicate and spawn it from the Server. May need to do a client-to-server RPC to make this happen from the Client but shouldn’t need multicast to create the bullet to all other machines.

If you are using one of the Character blueprints for your project, it can sometimes be misleading as to how to replicate non-character actors and get behaviors between clients and server, because the Character pawns have a lot of built in network replication, smoothing, and prediction code that takes the hard work out of getting them to work nicely on the network. However, this can also lead some to believe they can treat other Actors the same way and get the same results, but this is not the case.

I run bullet and hit explosion form the server now, it replicates. But now I face other issue. Before, when I hit object (character, ground etc.) it did git explosion. Now it only does when I play as a server, if I play with character, it dosn’t do hit explosion.

Okay - when you handle the Hit event on the server, then you can either multicast the explosion-making function, or spawn the explosion Actor on the Server and make sure the explosion actor’s blueprint is set to Replicate.

I can’t figure it out.

So basically these is my bullet (Run on server, Reliable):

My explosion (Run on server, Reliable):

Weapon trace( Run on own client, Reliable):

And my Projectile is simple BP:

And I would need, that projectile is not going trough object, when it hits. Otherwise, atm it goes trough body, walls, floor etc.

Another thing to try is on the hit, call the ApplyDamage function instead of making your own custom function to handle when the bullet hits something. This is a built in function of Unreal which I use, and it makes the server handle things.

Looking at your blueprint screenshots it looks like you are using Traces to do the actual hitting, and only spawning the bullet as a cosmetic visual effect to show other players that the bullet was fired. But you want the bullet to disappear after it has traveled as far as the trace does. is that correct?

Yes, exactly. Could’t figure out other way to do it. Just want to give small illustration to my shooting, but yes.
Later I will add sniper rifle, then I will make actual bullet, but will think about it later. Right now it’s important to figure out these.

You mean Event Hit? Should I add it to projectile?

Looking closer at your BP code, I think it could still work the way you’re doing it though.
Now if you don’t Spawn the effect in a Multicast that is called from the Server (not from the Client),
then whatever you Spawn has to be set to Replicate, or it won’t appear to the Clients.

In my game, I spawn the explosions in a multicast that is called from the Server, and it appears on all clients and the server.

If I change Server_OnEventHit from run on server to multicast, effect appears on shooting client, but still other client can’t see it.
And found out other glitch right now. If I run and shoot, player injure himself.

To make your projectile work more like a tracer instead of the actual damaging thing that your trace is, I think the way to do it is:

  1. set the lifespan to a value that will kill or hide the bullet when it has traveled the same distance as the line trace. I am not sure on the math for this but it will be the projectilemovement component’s speed setting divided by the trace distance or something like that. But I’m not sure how to convert unreal unit distances to make them match the math for the speed.

Another less performant but easier to figure out way is you could record the bullet’s starting location and every tick check against its current location, and if the length of the endloc-startloc is more than the trace distance, then kill the bullet.

  1. Your trace is doing the damage so you don’t have to make the bullet do it.

No, don’t choose between server and multicast, do BOTH.

  1. One client sends Server event.
  2. Server sends multicast event to all clients
  3. Multicast event spawns the effect on all clients.

Huh. I’m way toooo new for UE4 :smiley: Can’t make it work a t all. I think have f**k everything more, than made it work.

Did these, and still nothing. Probably need to find new way how to do it. Because yea, probably because of projectile, player can hit himself now :smiley:

That looks right but are you also spawning the effect in the red multicast event handler node for MultiCastSpawnEmitter? The blue one sends the multicast, but the red one receives and runs it.

Remember that the white execution wire continue running on the same machine. If on your client machine you run an execution wire to a blue Server event node, then it tells the Server to run its red node of that event, and then on the client machine continues running through to the next thing one the white wires.

Meanwhile the server is now at the same time executing starting from the red server event node, on the white wires coming out of it.

Making sure you understand that it does not switch to running the code on a different machine, from the same course of white execution wires. It starts a new execution on the target machine starting from the red node with the matching name.

I’m sooo confused :smiley:
Can you give me some code example, so I can understand how can I solve me replication problem?
I at least just found why my character was able to hit him self :smiley: At least fix that.

I cannot right now because I am not near my computer that has Unreal on it.

It’s ok. I can wait. I’m stuck with these anyway

Running on server and then multi cast it, actually solved my problem. Thank you!