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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Questions about function replication

Okay, I just want to understand for sure how some replication stuff works, specifically with function replication.

  1. How do they work when nested? If I have a function that is, say, set to Run on Server, and inside this function there is another function call, and this one is set to Not replicate, will it not replicate or will it inherit the setting of the "parent" function? If so, if I set it to anything other than Not replicate, will it use that setting or will it conflict with the parent? Is doing this sort of thing considered bad practice?

  2. If, for instance, in Event Tick, I call a function that is set to Run on Server. The stuff that I execute in Event Tick after this function will not Run on Server, right?

  3. Regarding Switch has Authority, if I want to make the client run something on the server, why would I need to use Switch has Authority instead of just replicating it to the server without checking if it has authority? Wouldn't the result be the same?

I hope I could phrase these questions well enough, and thanks in advance.

Product Version: UE 4.22
Tags:
more ▼

asked Jun 12 '19 at 11:46 PM in Blueprint Scripting

avatar image

Tryedz
64 11 12 16

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

1 answer: sort voted first

1.

When you call a function (or Blueprint event) that's replicated, your machine serializes the function parameters you passed in and sends a network message to the other machine telling it to call that function with those parameters.

At some future point (it's not instantaneous, due to network latency, and possibly due to the RPC call having to be resent if it's reliable and the packet containing the network message got lost), the server instance of the game will receive that network message, and the networking code on the server will call that function for you. But basically once that function gets called, it's pretty much just a normal C++ or Blueprint function at that point, and can do anything it wants.

There's nothing special about it, and you can call absolutely whatever you want on the server from there. You can call any function, whether it's replicated or not. You can also call client/multicast RPCs to let everyone (or just the requesting client) know about what just happened, that's a pretty common pattern in multiplayer games where the server/host has authority, clients will ask the server to do something, and the server will respond with another RPC that's either sent to the person who asked, or sent to everyone with the result. (For example, the client asks to open a door by sending an RPC to the server, the server replies with another RPC back to that client telling them that they can't because on the server, another player just kicked that door down and it doesn't exist any more)

On the sending client, you can absolutely call multiple server (or other) RPCs in a row, and they'll all get replicated. Ultimately though, to save on network bandwidth you're ideally going to want to send the smallest number of messages possible that will achieve the result you want.

If you have a server RPC "ServerFunction1" that then calls "ServerFunction2", the client doesn't need to call "ServerFunction1" and then ServerFunction2", it can just call "ServerFunction1" and let the server take care of calling the other function.

2.

When you call an RPC, all you're saying is "call this function on the server". Only code/blueprint that gets called from that server function will get called on the server. If you call a server RPC, and then do a bunch of other stuff that's not replicated, none of that will reach the server unless those functions also happen to be replicated.

3.

Switch Has Authority is most useful when you have cases where the code is run both on the client and on the server, and you want to do different things based on whether it's a client or the server. For example, your BeginPlay/Tick events can be called on both.

For example, you'll want to check for authority if you're going to call a multicast RPC, because if you're not the host/server, then you'll just call that function locally and not replicate it to anyone.

See the table in this documentation page: https://docs.unrealengine.com/en-US/Gameplay/Networking/Actors/RPCs/index.html

more ▼

answered Jun 13 '19 at 12:40 AM

avatar image

Deconstructor
91 1 3 2

avatar image Tryedz 2 days ago

Thank you, that clarifies a lot of stuff. I'll read more about this in detail.

(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