x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Replicate a variable/property client->server

I started experimenting with multiplayer for my project just yesterday and it's impressive how many things work "out of the box". What I am trying to do now should be pretty simple too, but I'm not sure how to do it.

I just want clients to constantly send a direction-vector to the server that represents the mouse-cursor-direction in world-space. I think there is no way the server can do this by itself, because (afaik) it can't know the position of a client's cursor, and even if it did, it would also need to know the client's viewport settings to make any use of it. So I want the client to have "authority" over this vector and it should be treated like any other "input" from the player controller.

The only way I can think of atm would be to write a server-function and call it from the client with the direction-value, only to set the property on the server. I would have to call that function every frame though and I suspect there is a better way to simply replicate a value from client to server. Any help?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 23 '16 at 02:23 PM in C++ Programming

avatar image

MaxPower42
643 65 82 116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Nope, rapidly calling an RPC to send to the server is the way to do it! You can call it less frequently than every frame if you want. Since it's a cosmetic value (at least, I'm assuming it's cosmetic, and not something used for authoritative decisions) I'd recommend calling it less frequently (maybe 10 times a second?) and using a smoothing/interpolation on clients (every frame) so that the value changing doesn't look jittery.

more ▼

answered Jan 23 '16 at 04:34 PM

avatar image

cancel
2.4k 101 72 123

avatar image MaxPower42 Jan 23 '16 at 05:38 PM

Oh, I see :)

Thanks a lot for answering! (Most of my questions never get answered...)

At the moment, I just need the value for rotating the player characters to their clients' mouse cursor in a kind of top-down setting. But since this is also relevant for, let's say, firing a gun in the right direction, I guess it's not just cosmetic.

Anyway, it's good to know I'm on the right track, so I don't have to rewrite everything later.

Would you say it's a good idea to store this value along with any values that I might add later inside a structure and send everything at once (only if needed, of course) by a single RPC call to reduce overhead? I don't know what an UE4 package looks like, but I guess the less packages, the better the efficiency.

avatar image MaxPower42 Jan 23 '16 at 07:20 PM

I have another question: Is it possible to call a function both on the client and server? The idea is to do this with a "startCrouch" function. Since the player actor is being replicated, it should be enough to call it on the server, I guess. But calling it on the client too would probably prevent a delay. At least that's what I'm thinking.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question