Client Call an Event on an Unowned Actor
I'm trying to build a multiplayer game that allows players to open a door when they click on it. Here's my code.
May not be the best for optimisation right now but that's an issue for another time.
Currently the door opens on both the server and the client, allowing both to walk through. But it only does this when the server clicks on it. The ActorOnClicked event is run when the client clicks on the door, but the ToggleDoor event it not.
My understanding is that this is because the client doesn't own the door actor, so can't call a function on it. I don't want to have to spawn every door for every individual client, partly because this makes level building difficult and because I think I'd be throwing any replication of the doors in the bin.
I'd appreciate any suggestions for solving this issue.
I'm still new to multiplayer programming and this is an attempt at learning some of the basics. I'd be very grateful for any assistance.
To make a successful client-to-server RPC (execute on server node) happen it must be called from within the blueprint of a class that is part of the connection-owning hierarchy, such as a playercontroller. Doing it from a blueprint that is not will unfortunately silently fail.
So usually I will have playercontroller get the Game state and use that to call the event on Server. So it runs on the server's gamestate and from there it finds the door actor and tells it to move.
The trick is going to be finding the door actor from within the gamestate to tell the door to either multicast or set repnotify the door open boolean variable (either of those methods will cause the change on all clients). This is where it comes in handy to set Tags on your actors placed in the level because then the server rpc event can do a GetAllActorsWithTag using a string or Name fed into it from the event node (you can add parameter variables to those to send information through) and just Get index 0 from the array that GetAllActorsWithTag node returns.
As for telling your timeline to play AGAIN every frame, 60 times a second, I think there are better ways but the networking is the tricky part so I focused my answer on that.
answered Nov 11 '18 at 08:01 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here