A little background.
We have a mutiplayer game running, we have two ships spawned. Each player can see each other moving around. My problem is when i try to fire an event for shooting the server side works perfectly and is replicated to the client as should be. But when the client shoots the client sees the changes but the server get nothing. This makes me think is some sort of input problem which is why I’m trying this now.
With this custom event (which is set to run on server if client) only works properly on the server version of the game.
I have just tried your suggestion exactly as the link shows using the same blueprints (Controller, Gamemode and then the level blueprint for the actual shooting). Using that method doesn’t appear to trigger the event on the game mode (doesn’t hit the breakpoint). Nothing happens when I shoot now.
Yeah the setup in the link doesn’t work. No idea why I even had the opinion that it could
You basically want this: A custom event in your player controller that is replicated to the server.
If you want to do arbitary interaction with objects you can use the setup described in the link with the fix below. The setup works like this: Create gameplay event dispatchers in your game mode. The player controller forwards client input to the server. Then on the server side of your player controller your forward the request to the game mode. Actors that want to react to that input can bind to the dispatchers in the game mode on the server side.
If you need to know who sent the request you can pass the player controller as an additional parameter.
You are actually running an execution path on the client side and one on the server side. Depending on the context of the blueprint it may lead to errors in the future.
You can remove the whole game mode blueprint - it is not neeeded anymore (keep the dispatcher)
Is “shoot to serv” set up with run on server?
And you want to link the exec pin of “shoot to serv” to the input exec pin of the cast, because otherwise the cast is not run and As CS GM may be null. (this may be the reason it is not working)
If i could get a list of players and compare the current controller to the list (Ie, check to see if player one or two) this should work as I can branch from “which player” to spawn bullet on the correct one. Or am I thinking about this the wrong way.
Add a player controller variable to the input of the dispatcher. When you call the dispatcher on the server side in the player controller you pass a reference to self. Then in the level blueprint you can use the get controlled pawn method to retrieve the player pawn and spawn a bullet using the pawn.
Awesome! Thank you ! Both players are now shooting bullets that each other can see. Major hurdle over! One small problem if you don’t mind.
I am getting the controlled pawn and spawning the bullets at its location but due to the strange way we have had to build the game I really need the position of the camera to be the location.
If i use that controller reference which is passed through and ‘get camera manager’ or ‘camera location’ from it, it only spawns on the server cam. If i use ‘get controlled pawn’, it fires in the direction of the correct pawn (server and client) but not from the camera location.
I cant seem to be able to get a camera from the controlled Pawn (which would be perfect). Any ideas?