Replication Problem


I’m beginer in simple network. I think i understand but some things are confuse. For example, I don’t know why the print is replicated ? I always use print for debug and i can’t use it in network ! Debug is hard too. So how do you debug network ? There is no send/recv information ?! How do you want to code network without any debug possibilities ?!
So i try to debug my first network game, normaly i never ask help but here is impossible to understand because no debug…

I’ve a blueprint actor with in it : on clic → event run on server → set Selection true.
“Selection” is a boolean replicated in the blueprint actor.
Now i put 10 instance of the object in the scene. If i put a print in the onclic, it print. So clic work. It can geve the name of the object.
In the level blueprint, on the tick a run on server event :
for all actor of myclass, get selection and tell me if it’s true.
But if i clik the actor on the server, it print true. It’s Ok.
In the client it never print true… why ? All is replicated !
I tried multicast instead of run on server but it same.

So what’s wrong ? how can i debug network ?

Probably the Owner of these actors are not valid Clients.

Here Look at the page 66 - Ownership

Odd that you can’t use PrintString in multiplayer. It should even prefix where the PrintString is called like “Server:HelloWorld” or “Client2:HelloWorld”.

Thanks guys for your help. I don’t want to use gamestate or playestate. It’s a simple one client versus one client/server, i don’t think it’s necessary to understand this hard concept for now. I’ve coded a lot of client/server in C++ with socket : It’s just send, recv, it’s easy to debug. Just the threading is hard. So here we don’t worry about thread, it’s cool.
I’ll try to make a simple tchat, maybe i’ll understand a bit better.
And if it work, i can use the send/recv string function of this tchat to make simple 1vs1 applications by modifying variables on each client/server without replication but like i did in C++. It’s like i proceeded with socket. Just send : go on 10;15;151, hop it did on recv. I made my own events that it didn’nt exist in fact.

But i stopped C++ for 15 years because i didn’t really understand references and a lot of bugs with threading and sockets. Now with blueprint i understand it because it’s more visual !
In fact i wasn’t a C++ coder but a C coder with some C++ functions.

But i don’t understand that :

Has i heard there is a a problem of “owner”. I don’t know why i can’t simple send input from client to server to make the server moving something that will be replicated on client. If i do it on server it work. But my client input is not detected on server because the server is not setting my bool to “true” in the replicated object of the client. It looks that the replicated object on the client is not the same as the server… i don’t understand.

Hi, without some images of your blueprint code one can only guess what the problem is…

First of replicating means that when the state of the variable changes on the server it will update to all clients. That goes only one way (it’s to prevent cheating from the clients).
So you would have to use a “Run On Server” event. Then this event will be replicated from the client to the server and will execute on the server. But the only client that can call a “Run On Server” event is the client that owns the actor (again to prevent cheating in multiplayer).

So, as far as I know, by default the client only owns it’s player controller and it’s controlled pawn. You can use “Set Owner” on the server to change the owner of an actor.

Documentation on RPCs (like “Run On Server”): RPCs | Unreal Engine Documentation
And you should read this: Networking Overview | Unreal Engine Documentation

Ok, hummm if i understand : I’ve to tell to server : give me rights, like chmod … security… security always complicate everything (and it always cracked). Oh ! and Can i set owner directly in client with a “run on server” event ? (on a actor i own for sure)

Thanks for this information, it help me to understand
Why replicated objects are not directly set to his owner on create ?

Hmmm, what do you mean? You should spawn replicated actors always on the server and never on the clients (cause when they are set to replicating and the server creates them they will also be created on the clients).
But when you spawn them on the client they will only exist on that client, and not on the server, not on any other client.

Basically the workflow I use is for stuff that is attached to the client (such as his weapon actor) I set the client as owner when I spawn them.
For interaction with the world (other replicating actors) I put that logic either into the player controller or into the controlled pawn (I do it mostly in the controlled pawn but when you want to switch that controlled pawn in the game you would want to put all the logic into the player controller, cause the player controller persists).
So for example when I want to open a door, the client uses a Run On Server event (that logic is in the controlled pawn for example the Third Person Character), then the server sends an interface call to the door actor and the door opens.
There sure are better ways to do those things, but I don’t know what I don’t know :slight_smile:

Hummm i think i get it. It’s because it’s an actor i put on the scene manually. As i understand, i must spawn it with a run on server event. I’ll make some tests and see how “set owner” can be setup if it’s need.
That’s because when we use mouse to code, we drag and drop things but we don’t see the code or blueprints. It’s hidden so it certainly a bad initialisation that is not “run on server” … Ok ok. Even if the class is “replicated”, it doesn’t work on client i see.
Thank you all for the help, i’ll check that now.

The general rule is… If something needs to be spawned it MUST be done on the Server ALWAYS (for example spawning a vehicle into the game). But if its something cosmetic you have a choice (particle explosion FX etc). If everyone must witness the FX, then you need to do a Multicast (requested by the Client) but triggered on the Server… BTW: You can test things out, its a useful learning experiment. If I remember right, If you spawn something on the Client, it will spawn, but there will be gotchas sometimes like no working collision on the Client, and other Clients won’t know anything about it at all obviously (can’t remember what the Server sees now)…

If you are working on Multiplayer, chance are you are working with a listen server in the editor. So

  1. Make sure what ever changes you want in the level , goes from server to client. Means any value update should be happening on the server
  2. Make sure your variables are replicated and it can be accessed on server to change its value.
  3. You can use the Print Text Node wherever you like, in multiplayer it will give you Server or ClientName: Log Message.

Yes, thank you everybody : it work in multicast with non spawned actors. Now there is a lot of bugs because some things are made two times, i need to use a switch authority to verify who execute. I see it’s hard to put network on a game that it have no network. So we must think network before coding. I’ll restart from scratch. Training with a simple tchat and see if i use the concept of UE4 network or if i do my own with simple send/recv data and i’m master of everything.