Download

Networking in UE4

Hello everyone!

I have some questions about how to start up and to create a networking game within UE4. I haven’t found any resources for this while looking around, are there any tutorials on this subject out there?

Best Regards

Here are a few things I’ve found:

https://docs.unrealengine.com/latest/INT/Programming/Gameplay/Framework/Networking/Replication/Implementation/DynamicArrays/index.html

I’m still trying to shake a stick at it, but heres a quote from one of the dev’s

Hey there,

Your best bet is looking at the ‘Shooter Game’ example. That example can get you started on building what you need. :slight_smile:

Take a look at the C++ within the files, rip it apart and try to create your own version. :slight_smile:

The easiest way to test locally is to load up the editor and click the drop down arrow next to the Play button in the main editor window. There is a box to specify the number of players, put that to 2 then press play and by default it should run the game with the main viewport being the host and a second window will be openned and automatically connected to that host as a client.

One thing to be careful of is that if you are using any of the templates spawn logic there is a bug where players will not spawn if there is a player already occupying the player start location and it will not search for other playerstarts. This means the clients will all start in spectator mode with a first person flying camera. To fix it you will need to write your own spawn point selection logic, or if all you want is to check the connection actually works you can run the game, move the host player away from the player start then open the console on the client by pressing ` or ~ depending on your keyboard setup and type reconnect. Your client should then spawn properly :slight_smile:

I also saw that explanation on the Epic Networking Tutorial. I tried, but it didnt work.

If i try the First Person template, set number of players to 2 and “play”, there is no other player on the map. Everybody of both is alone on the map.
If i do the same on 3rd Person template, there are 2 Players on the map!!
But when i package it and try it online on 2 PCs, i dont even see the 2nd player on 3rd Person template.

Why?

I tried the same thing, and was also wondering why the 3rd Person template seems to have replication working, and the first person template does not ?

Could anybody tell what is missing in the First Person template or if it’s generally not working for some reason…

Thx

First thing that comes to mind, is because the first person template makes the meshes visible only to self, so you think you are in worlds alone, but in reality you are both correctly in the same game, the meshes are just set to self visible only where as the 3rd person templates are not, that is my first guess

Not too far off Pada but basically in the third person the mesh needs to be seen by the camera as if it is a separate entity. In the FPS the players are under Mesh1p meaning a firstperson view and are hidden from anyone else. But if you mess around a little you will notice that you can in fact collide with the other player.

It would be nice if more replication and the third person mesh was already setup in either the code or the blueprinted version. Best bet is to take a look at shooter game in the shootercharacter code and blueprint and see how they set it up.

This is currently my biggest pain point with UE4. The C++ written networking documentation are bunch of notes on the wiki\forums\answer hub. I feel there is too much emphasis on blueprints. I think there needs to be a balance between the two to develop a game in UE4.

The get around this, I’ve been creating my C++ version of Billy’s excellent Adding Networked Features to 3rd Person Template video. It’s not a quick process reading the Unreal Tournament and Shooter source code and then filling the gaps with the forums.

My steps:

  • Read every scrap of written documentation
    ote I can find.
  • Watch Billy’s networking blueprints videos. Just watch and absorb. Whether you’re developing in blueprints or C++, he highlights issues that you need to think about at a high level.
  • Then develop the C++ version of Adding Networked Features to 3rd Person Template while watching it.

This has worked quite well for me. It’s not ideal but it’s just part of being a programmer sometimes - you’re not always going to get your hand held for you.

For the first person C++ template I just added a skeletal mesh to the character blueprint so I can see what’s going on.

9c3b107b71fa3c0dbee795ff54c83e41abf27814.jpeg

Current work in progress: C++ version of Adding Networked Features to 3rd Person Template.

Capture.jpg

Bump.

Lets say I host a game on my computer 192.168.0.18 (18 is the one my PC has) I open up 7777 and allow all traffic to come through from. So my computer is listening on this IP. How

Now lets say my friend has the same EXE. and when he runs the “Show Servers” it will loop through all the servers on the LAN, will it find my game, and will it be able to join my game?!!!