Server Replication and Events Questions (Multiplayer Games)

1- If I call an event on the server to perform a task (Simulate physics on an object) it will not work because I need to call a multicast event as well so that it runs both on the server computer and on the clients’ computer and this is also true for calling variables.

2- But if a new player enters the session will all changes made to server before this player enters the server be downloaded to him? Or do I have to create custom events to get the state of the object and variables on the server to set for this new client that joined?

3 - Note that I always replicate all variables and static meshes and blueprints as well.

4 - If a new proprietary client that entered the session obtains a variable that has been set by the server, before it obtains this variable, the new client will need to obtain the server variable to make this owner client see the variable when calling a client event for the server to get the server variable and set it on the client itself? do I have to do these dynamic custom events to allow the multiplayer game to work correctly for players who join later?

Or will it be that automatically when a player enters he will load everything that is replicated on the server and changed and set for himself? If not, now I understand why some games wait for all players to enter before starting the match and without allowing new players to enter until the match restarts and when the game is over the game simply restarts the level. But I still have many doubts.

5 - Why do some events need to be called in multicast to work on clients and why can some events be called only on the server that is automatically run on clients?

That’s all for now, I’m developing a game but these doubts shake me a little.

Wow that took some time to read

Firstly **never let a small hurdle stop you **

Secondly multicast functions are normally used in my case for player called functions

Eg in a shooter a weapon shoots and the function calling the animation needs to be multi casted

Thirdly multicast event I could be wrong needs to be called from the server

Fourthly I don’t think you need to manually get current state of level it should just happen well In my case it does

Lastly if you keep having trouble I think it be best to just have a que and after it’s full join map

The problem is that some events if I call only on the server they do not work on clients so it is necessary to create a multicast event. I fear that if a new player enters, the actor’s status exulted before by that multicast event will not be downloaded to him because the server did not receive the event that only works on clients and the new player also cannot load a state from an actor who received an event only for clients since when the player entered the server, the server had not received this event in order to download to the new client, this new player would need to be on the server before this event for clients to be called.

If so, the only way out would be to run a custom event when a new client enters the server, the client will look for another client preferably with a good ping and call an event passing through the server and even the target client executing an event on the owner client target to obtain the status of an actor who has received predetermined events that did not work on the server to call the event again but this time only for the calling client.

What event / function are you trying to call exactly?

If a server function is called it eg weapon animation other players can’t see it unless you multicast it

Running on server alone won’t be visable to other players that is what multicast is for

I am creating an event to add instances of an instance but it only works when I call remotely, but I also call on the server, if a new player enters he will see the instances? since the event was also called on the server? even if this event being called on the server individually does not work on clients that are currently on the server, if a new player enters the server will he see the instances because the event had been called on the server?

Hi, you might wanna search for “ue4 in progress join” and maybe some general networking tutorials with UE.

First thing that comes up there Join in progress - C++ Programming - Unreal Engine Forums is nearly the same you’re asking.

And you might wanna watch this tutorial series here on UE and networking - YouTube

Anyway if I use “rep notify” it just creates a function for that variable and then I needed to create a dynamic event within this function that can be called by a new player who enters and I will have to do it for all variables the actors, it is not at all efficient, unfortunately I did not find a possible way to make the server take all the variables of all the actors at the same time and call back to the owner client.

The tutorials did not solve my problem.
I am
staying
without
exits.

Is it strange if inside the variable’s function: “On RepNotify” I will have to call the event related to this variable? Example: [Actor Variable reference> On RepNotify> (Branch Have Weapon?) TRUE = Call multicast Parent Actor Reference variable> Switch Has Authority> Remote> Attach “Weapon” to Parent Actor Reference (The Character]

This will be confusing, I will have several events related to these actors and it will be a very large graph for each state that the actor is in the game I will have a variable to allow how the RepNotify event will call for the new player. It will be confusing in addition to causing conflicts between dynamic events.

any idea??

These might help

Anything that correlates to the state of an object or the game should always be handled via a replicated property.

Not adhering to this principle will always cause problems for clients joining a game that is in-progress, not to mention issues with network relevancy and packet loss.

RPC’s and Events should only be used for one-time events that do not affect the long-term state of the game.

1 - If the UObject and the property are replicated, there is no need to call a multicast as the property will get replicated by itself.

2 - All replicated property (REPLIFETIME) will be send to the client with their actual values and updated when changed. There’s no need for multicast. You don’t need to bother about replicated properties replication. They will be synced with the server.

3 - This is a bad idea. Only replicate what is needed. Replicated properties use server’s CPU to check if it has to be sent to clients.

4 - As stated above, if the object and its property are replicated, it will be done automatically and all properties will be up to date. You can still add repnotify to call custom code on client once the property has been replicated.

5 - Almost all multicasts can be replaced by replicated properties. For example, you can call a multicast function when game start or use a replicated boolean with a repnotify. The repnotify and the multicast will both run on the clients to handle game change status. Most of the time, repnotify is easier to use and work out of the box, but it’s not always the cleanest way.

I needed to create a dynamic event
within this function that can be
called by a new player who enters and
I will have to do it for all variables
the actors

Example: [Actor Variable reference> On
RepNotify> (Branch Have Weapon?) TRUE
= Call multicast Parent Actor Reference variable> Switch Has
Authority> Remote> Attach “Weapon” to
Parent Actor Reference (The Character]

Seems like way too much of a workaround for me :slight_smile:

In the specific example of the weapon. You could create an object reference to a weapon inside the pawn. Then mark this weapon reference as “RepNotify”. Then when you pick up a weapon or equip a weapon you change this weapon reference. Therefore the “RepNotify” function will automatically execute on the clients. Then you would do your attach logic directly inside the “RepNotify” function, or inside the “RepNotify” function call the function you have for the attach logic.

Is it possible to make On RepNotify call only the event for the player who joined? Example: “Get All acotrs of class” third person character he will get the last index and call remotely and if the puppet of the last index is controlled locally the event calls only to him, but I don’t know if the function On Rep Notify is called on the server or remotely or if it is already called on the player who entered. I did tests with “Print String” When the client entered the server and nothing else happened I called a multicast event in this function and called the client who entered normally.

Yes, so in this case even replicating all components and actors, still, I will need to call the event when the Rep Notify function is called to restore the actor’s state to that player even though the event was called on the server before that new player log in.

I found the tutorial helper, although I wanted there to be “Rep Notify” for component engine variables Example: “World Transform Variable” of a static mesh could be set to Rep Notify but it would only be possible by modifying the engine, this would save a lot job. Some things might not work and would need to create a dynamic event exclusively to restore the state, but it would help a lot if it were possible to notify basic variables of a component, actor … I know that many variables are associated with events.

RepNotify is called on a client, after the property has been replicated nothing more nothing less.
So if a player joins the game, the repnotify will be called. If you want to call a function only for one client, you have to make your RPC function OwningClient and not Multicast on the targeted client’s pawn or controller.

Thank you all for helping me.