My question is pretty straight forward. I want to have an object that will be moved for all players when one of them presses key on keyboard (like F or somehing).
I’ve tried many ways but the result is mostly that when server presses F object normaly moves for both, server and client. But when client presses F it only moves for him, not for server. And when server presses F again, from client side it looks like the object just teleported to its position on server side.
So is it possible to achive something like this? To have one object controlled by multiple players?
The actor is owned by the server, so to move actor from client you need to ask the server to move the actor. Client can’t directly move the actor because it is on the server side. To achieve this you need to have a custom event on the server that’s set to run on server, and then you can call this event from the client and ask the server to move actor. But you can only do this from blueprint class that is replicated between client and server. You can’t call for GameMode and try to execute custom event, because GameMode exists on server only.
I know about events happening on server and I did those. The thing is that I’m not able to achive the same movement on server and client. It looks like it’s replicating from server to client but not the other way. I’ve tried making custom events but maybe I’m doing something wrong 'cause I’m stuck and have no ideas how to accomplish my goal.
If you would be so kind, can you maybe try doing it yourself and see if you can find a way to move the same object in real time from server and from many clients?
Ok, I made a little sample project for you. In the project go to FirstPersonBP/Blueprints and open FirstPersonCharacter. Inside of it you will have three numbered commented parts , that’s the logics for server client functionality. To test it press play and shoot yellow ball and you should be able to see the ball shoot from server and client views. Oh I forgot to untick Run Dedicated Server under play options if you want to see server view please disable that check box.
Ok, I understand it very well now. But there’s one more thing. I know how to spawn actor and other things, but I really can’t find a way to get actor reference from a level into FirstPersonBP. I have to have this reference to be able to move this actor.
I tried this and I am just getting an error:
So, how to get level object reference into another BP, or maybe there’s better way to do it?
Take a look at this [Forum post][1]
in 8th post from the top, you can see how to make a line trace from player character camera. You can use this to get the reference of the actor you are looking at and then you can send the reference to server so it can move the selected actor. I don’t really know any other way to get reference from level in blueprints. In c++ there are options, but blueprints are a bit limited unless you use Level Blueprint. You could get the reference from level in level blueprint and then pass it to the character. Like this
I’ve tried both of these methods and I’m getting those errors:
(first one is for method on your screenshot, second for LineTrace)
Maybe it’s 'cause that I’m using AddActorLocalOffset, maybe I have to use other method to move this actor.
I added some changes to my sample project. Download this file from GDrive link and close the UE4 Editor, go to sample project NetworkingSample/Content/FirstPersonBP/Blueprints, remove FirstPersonCharacter.uasset and place one from the link in it’s place. Launch the editor and press play and aim at the cubes, placed in the level and press shoot and cubes should change location on click. It’s a bit buggy, but you can get the idea.
I think that’s an answear to my question and this is the easiest way to get this reference. Now that I know this I am able to move the same actor from server and client side in real time.
Thanks a lot, I seriously appreciate your help and effort you have put to make my blueprints work.