Hello,
I am working on a networked shooter game, but I’ve stumbled upon a curious issue, if I pass an integer variable with a value of zero through a multicast, it seemingly causes the end-client’s local variable to be implicitly overwritten by the one passed through the multicast.
Here is my set-up:
First, the client that fires a bullet calls the function to do so, then tells the server to do the same. As you can see, the server is given an extra value, the player’s ID.
This is what sets the player ID. I’ve very thoroughly tested it (as a matter of fact, the player ID int is printed when you jump, so I know that at all times that each client still has the correct value assigned). The delay can be ignored.
Second, the server fires a multicast with that information. We don’t spawn a bullet in the server because multicasting executes code for the server too.
Third, our multicast checks if the original player’s ID (the initiator) is not equal to OUR client’s ID. The goal here is to ensure that we don’t fire the bullet twice, since our original client already did so before calling the server (why? Because that way lag can not get in the way of a responsive experience client-side, bullets are mostly deterministic, so no need to actually sync them across clients after spawning).
By all accounts, this should work. After all, “Player ID” in the context of a multicast is the current client’s, not the original. Indeed, this works correctly when a player without an ID of 0 fires a gun, all other players spawn a bullet too, without doubling the ones the original player fired.
However, when player zero fires a gun, nobody else does. Every other player things they are client zero too. Even more strange, this does not seem to permanently overwrite the client’s Player ID, they still know their true ID after the fact.
For testing, I have these two printouts made:
The top one just prints the player ID when jumping. The bottom one shows you the value of initiator and player ID.
This is what it looks like if a client with a non-zero ID fires a gun:
This is what happens when client zero does it:
The issue happens regardless of whether the server is dedicated or listen.
It could also be (based on client zero’s printout) that the multicast does not reach the other clients, but that seems out of the question since it is a default Unreal Engine node, such a behaviour is not documented anywhere I know, and I am not one to blame my tools when something goes wrong. The issue must clearly be in my set-up, but what part of it is failing and why is something that evades me at the moment.
I have also tried to replicate the value of player ID, but that has had no effect either.
I would greatly appreciate any advice. As I have been wracking my brain over this matter for the better part of the day.
I’m aware that my approach is unorthodox, or at least it seems to be from other forum posts and tutorials I’ve seen. If completely changing my implementation for client-side projectile spawning is a valid solution, I’d be happy to consider it, too. My goal is just to ensure a responsive client-side experience, there’s no strict rule that says I need to use a player ID check or anything of the kind.
By all accounts, I expect my theories as to what is happening and why to be proven terribly wrong. Unfortunately, I can not know what I do not know, I hope you can all teach me to create better network blueprints.
Thank you.