Why does my server execute code on the client?

Hey all, I’ve decided to journey into multiplayer on a side project and am having a hard time understanding why my server is executing code and print strings on clients. This is mainly an issue when hosting a game. I’ve checked replication settings and event experimented with changing them around and am getting the same behavior. To contrast, when I host a game from the client it works perfectly fine as the server/listen server can connect to it.

TLDR: I’m experimenting with multiplayer and when I press my “Host Game” button, it executes on the clients as well no matter what my replication settings are.

Here’s an image of my setup:

I am not fully sure, but you should likely use this if you want it to only run on the server:
bild

I haven’t had a chance to even test the code, but how does it fair if you just use a normal custom event without any replication. Does the Is Server check still execute?

Hold up, why do you run both Print Strings into the Widget creation? Do you basically just test the setup of how the event nodes work?

Thanks for the reply!

The Is Server check does execute, however if it runs on the server somehow it’s also running on the client. As for the print strings into widget creation, yes that was essentially the idea, I wanted to check if the client and the server would both print something different. In my case, they both printed both of them. I event went as far as to print string the GetPlayerController and noticed that all clients had the same one which was weird but I guess its expected?

I recreated what you have and are experiencing the same thing. It returns both values for me, and I think I know why. It is basically this:

When you start the game you will load into a level and thus you become your own server and host. This will therefore print the server message (I am the server). However, what happens behind the hood when you use the built in feature in Unreal Engine to play as listen server and have more than 1 number of players, is that they will connect to one host (Connecting to a level and thus running BeginPlay again). This will cause them to print the “I am not the server”.

Finally, you may ask yourself, why is the host / listen server printing Client: “I am not the server” message? Well that is because the server will print everything all of the other clients does.

So, everything is working as intended and we are just confused because of the execution and flow of how it works! I hope this helped, and please let me know if you didn’t understand my explanation and I’ll try to be more detailed.

1 Like

Ahhh! That makes so much more sense given that explanation. The optics of what I was doing felt right during implementation but appeared wrong due to how the system is intended to work. Thanks for giving this a look! It’s helped tremendously!

No worries! Thank you very much for posting as it helped me figure it out as well! I am thinking of diving more into multiplayer now, so this was very helpful!

Best of luck with your project! :slight_smile:

Start working with Local and Remote Roles to identify/restrict executions in logic.

For example when loading UI for characters you need to remember there are 3 general copies of you the Player.

There’s the Autonomous Proxy, the one you control on your screen.
There’s the Authoritative Proxy, the server “authoritative” copy.
And there’s the Simulated Proxy, You on all other clients.

You only want to load UI on the Autonomous Proxy… a controlled client on a local machine.

If you are loading the UI in the character class then → Get Local Role == Autonomous Proxy → Load UI.

If you don’t do this the server and sims will load the UI for their copy AND theirs will overlay onto your screen…the sims will anyway.

e.g. 4 player server, each client will have it’s character and 3 sims. Thus 4 copies of the UI running and overlapping per client.


Roles are your friend.

1 Like