this page will show you how to:
- obtain a sample UE4 game project via the Epic Games Launcher
- configure multiplayer project to use websockets
- play a multiplayer game session with desktop client host and HTML5 client
- smash texture sizes
- view modes in editor
normally, game developers (who do not have much or any programming experience) can download the Epic Games Launcher to get the Unreal Engine Editor and to start making games with it.
you can also download a number of sample projects from the "Learn" that's available via the Launcher.
we will use one of Epic Games sample projects from the Launcher's Learning center to continue with this advanced demo.
to obtain the Launcher, download it from:
- https://www.epicgames.com/store/en-US/download
- Windows and Mac
- https://lutris.net/games/epic-games-store/
- Linux (requires Wine)
after opening up the Launcher, you will be required to Sign In in order to use it. use your Epic Games account credentials you've used when linking your GitHub account (we saw how to do this HERE).
to download the ShooterGame project:
- open Epic Games Launcher application
- goto the Learn tab
- scroll down to the Games section
- click on ShooterGame to view the project
- click on Free
- click on Create Project
- pick the path to download the project to
- in this example, i have put ShooterGame in the same folder where Engine
is -- i.e.
.../ue4-4.24.3-html5/ShooterGame
. it doesn't have to be there. but, for this demo, you can put it there to follow along these instructions.
- in this example, i have put ShooterGame in the same folder where Engine
is -- i.e.
- select the engine version: 4.24
- click on Create
at the time of this writing, we need to patch one file in the ShooterGame project. (by the time you read this, this may have been fixed. but, just in case it is still broken on mac and linux, you will need this fix.)
- edit the following file:
.../ShooterGame/Source/ShooterGame/ShooterGame.Build.cs
- add the
"RHI"
module to thePrivateDependencyModuleNames
array - it should look something like this:
- add the
. . .
PrivateDependencyModuleNames.AddRange(
new string[] {
"RHI", // ADD ME!
"InputCore",
. . .
when ever starting a new project that contains source codes, i usually run the
GenerateProjectFiles
command (that we saw in Generate Project/Make Files).
this may have been done for you automatically when using the Epic Games Launcher.
but, it's good practice to do this when ever you start playing playing with new projects that contain source codes. and this example is a good one to start with.
- open
CommandPrompt
to ue4-4.24.3-html5- e.g.
cd ...\ue4-4.24.3-html5
- e.g.
- re-generate the visual studio solution file
GenerateProjectFiles.bat
- open the generated visual studio solution (UE4.sln)
- in Solution Explorer-> Solution -> Games,
right click select
andbuild
ShooterGame
- in Solution Explorer-> Solution -> Games,
- open
terminal
to ue4-4.24.3-html5- e.g.
cd .../ue4-4.24.3-html5
- e.g.
- re-generate the xcode project file
GenerateProjectFiles.command
- open the generated xcode project (UE4.xcworkspace)
- select target ShooterGame
- and then select:
- Menu -> Product -> Build For -> Running
- or
Command + Shift + R
- open
terminal
to ue4-4.24.3-html5- e.g.
cd .../ue4-4.24.3-html5
- e.g.
- re-generate the Makefiles
GenerateProjectFiles.sh
- and then:
make ShooterGame ShooterGameEditor
when the build completes, fire up the Editor:
- note: i like to see the
stdout
prints (to know that the Editor is still running)- using
-log
parameter to view this
- using
...\Engine\Binaries\Win64\UE4Editor.exe ShooterGame -log
open .../Engine/Binaries/Mac/UE4Editor.app --args ShooterGame -log
.../Engine/Binaries/Linux/UE4Editor ShooterGame -log
TIP: put the command in a shortcut (or alias, script, etc.) for future use!
we saw how to do this back in the first HowTo:
just like Starting with UE4 Editor, we will first build for the Desktop to ensure the project (still) "works" before trying other platforms.
- it is much easier to debug or trying to diagnose any problems on the "Native Platform" first (i.e. the desktop)
ShooterGame is a fully fleshed out project that can host network games.
-
usually, a server is used to host these game sessions
- Unreal Engine make these and are known as "UE4 Dedicated Servers"
- an example of this was done in the previous HowTo: UE4 Multi-player Testing With HTML5
-
another way to host game sessions is to have the running application open a listening port and perform the same functionality as a Dedicated Server (many console games do this)
- we will be doing an example of this here
finally, the HTML5 client will need to connect to a listening host.
NOTE: UE4 HTML5 will NEVER be able to "host" a game (it can join them, but never host).
for the purpose of this demo, we are going to use the "desktop game client" to open a listening port to host a session.
- the HTML5 client will connect to this to play a networked game
in the previous previous HowTo, it was mentioned that the clone of a special branch based on Release-4.24.3 was made with the HTML5 platform files already populated. this includes config.ini files.
in this HowTo, we will go through the steps to make UE4 networking projects work on the HTML5 platform in detail.
normally, all desktop and most console platforms will be using what is known as the Unreal Engine IpNetwork NetDriver for network communications.
- this needs to be change to use the WebSocketNetwok NetDriver (1)
- add the WebSocketNetworking.WebSocketNetDriver (2) settings to the Engine
- and finally, disable Packet Handler Components not supported with websocket (3)
- one such example is the SteamAuthComponentModuleInterface
we will now go over each of these (1-3) steps one by one.
in the following files:
- Engine/Config/BaseEngine.ini
- ShooterGame/Config/Windows/WindowsEngine.ini
- ShooterGame/Config/Mac/MacEngine.ini
- ShooterGame/Config/Linux/LinuxEngine.ini
disable all existing NetDriverDefinitions
- by placing a
;
(semicolon) at the start of each line- this is known as commenting out a line (which "disables" or "hides" them from being used)
in BaseEngine.ini, it would look like this:
;NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/OnlineSubsystemUtils.IpNetDriver",DriverClassNameFallback="/Script/OnlineSubsystemUtils.IpNetDriver")
;+NetDriverDefinitions=(DefName="DemoNetDriver",DriverClassName="/Script/Engine.DemoNetDriver",DriverClassNameFallback="/Script/Engine.DemoNetDriver")
next, add the WebSocket NetDriver - like this:
;NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/OnlineSubsystemUtils.IpNetDriver",DriverClassNameFallback="/Script/OnlineSubsystemUtils.IpNetDriver")
;+NetDriverDefinitions=(DefName="DemoNetDriver",DriverClassName="/Script/Engine.DemoNetDriver",DriverClassNameFallback="/Script/Engine.DemoNetDriver")
NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/WebSocketNetworking.WebSocketNetDriver",DriverClassNameFallback="/Script/WebSocketNetworking.WebSocketNetDriver")
remember to also do this in WindowsEngine.ini, MacEngine.ini or LinuxEngine.ini (depending on the system you are using - or do it on all of them if you are not sure).
note: BaseEngine.ini has been done for you (if you're using the special branch)
repeat: ShooterGame/Config/{Windows,Mac,Linux}/{Windows,Mac,Linux}Engine.ini will NEED TO BE EDITED with these changes mentioned above.
at the end of BaseEngine.ini (and only this file), add the WebSocketNetworking.WebSocketNetDriver settings at the end of the file:
[/Script/WebSocketNetworking.WebSocketNetDriver]
AllowPeerConnections=False
AllowPeerVoice=False
ConnectionTimeout=60.0
InitialConnectTimeout=120.0
RecentlyDisconnectedTrackingTime=180
AckTimeout=10.0
KeepAliveTime=20.2
MaxClientRate=15000
MaxInternetClientRate=10000
RelevantTimeout=5.0
SpawnPrioritySeconds=1.0
ServerTravelPause=4.0
NetServerMaxTickRate=30
LanServerMaxTickRate=35
WebSocketPort=8889
NetConnectionClassName="/Script/WebSocketNetworking.WebSocketConnection"
MaxPortCountToTry=512
again, this has been done for you if you're using the special branch
in the following files:
- Engine/Config/BaseEngine.ini
- note: as of this writting, this is not seen in BaseEngine.ini -- but, it is mentioned here just in case you see this in the future...
- ShooterGame/Config/Windows/WindowsEngine.ini
- ShooterGame/Config/Mac/MacEngine.ini
- ShooterGame/Config/Linux/LinuxEngine.ini
find any PacketHandler Components sections, and disabling them by commenting them out.
for example, in ShooterGame/Config/Windows/WindowsEngine.ini -- this should look like this:
;[GameNetDriver PacketHandlerProfileConfig]
;+Components=OnlineSubsystemSteam.SteamAuthComponentModuleInterface
;
;[PendingNetDriver PacketHandlerProfileConfig]
;+Components=OnlineSubsystemSteam.SteamAuthComponentModuleInterface
note the
;
(semicolon) at the start of the line indicating this line is disabled (commented out)
using the same steps outlined in Build Sample Project
set the build type:
- Menu bar -> File -> Package Project -> Build Configuration
- select
Development
(i.e. keep the build type the same for all platforms)
- select
finally, package for your desktop
- Menu bar -> File -> Package Project -> Windows/Mac/Linux (etc.)
- select the folder where the final files will be archived to
NOTE: on linux, you may need to enable it as a supported platform - see (HTML5) screenshot below to find where to enable it
now, using the same steps outlined in Build Sample Project
set the build type:
- Menu bar -> File -> Package Project -> Build Configuration
- select
Development
(i.e. keep the build type the same for all platforms)
- select
finally, package for HTML5
- Menu bar -> File -> Package Project -> HTML5
- select the folder where the final files will be archived to
as we have seen in the previous HowTo's multi-player testing,
we will run this project in windowed
mode from the command line.
-
run the game in a windowed size screen (i.e. not full screen)
- using
-windowed -resx=800 -resy=600
parameter to do this
- using
-
again, i like to see the
stdout
prints -- to know that the game is still running- using
-log
parameter to view this
- using
- open
CommandPrompt
to the location where files were archived to- e.g.
cd ...\ShooterGame\WindowsNoEditor
- e.g.
- run executable
ShooterGame.exe -windowed -resx=800 -resy=600 -log
- open
terminal
to the location where files were archived to- e.g.
cd .../ShooterGame/MacNoEditor
- e.g.
- run executable
open ./ShooterGame.app --args -windowed -resx=800 -resy=600 -log
- open
terminal
to the location where files were archived to- e.g.
cd .../ShooterGame/LinuxNoEditor
- e.g.
- run executable
./ShooterGame.sh -windowed -resx=800 -resy=600 -log
TIP: put the command in a shortcut (or alias, script, etc.) for future use!
for the purpose of this demo, open another client in windowed mode.
then, in the first game window, select:
- in MAIN MENU -> HOST
- set NUMBER OF BOTS to 0 (zero)
- click on FREE FOR ALL
now, in the second game window, select:
- in MAIN MENU -> JOIN (may have to click on JOIN twice)
- click on SERVER
- wait for your server to show up in the list, and then double click on it
you should now see the two game clients in the same match.
now, let's get the HTML5 client in the same match.
using the same steps from launch the HTML5 client from the previous HowTo's multi-player testing example.
in git-bash
(for windows) or in the terminal
(for mac or linux), you can
use python's built in web server to host the files quick and easy.
# remember, this is an "example" path (see "archive to" notes just above)
cd .../ShooterGame/HTML5
python -m http.server 8000
#python2 -m SimpleHTTPServer 8000
and using almost the same steps from chrome or firefox above:
-
open browser to http://localhost:8000/
- click on the relevant HTML file ( e.g. http://localhost:8000/ShooterGame.html )
-
join the desktop match:
- NOTE: due to the way ShooterGame was designed, the JOIN mechanism will NOT WORK with the browser
- SO, we are going to use the
game console
command line we've seen in testing muti-player on HTML5 in the last HowTo - open the
game console
command line, by pressing the tilda key (~
)- type:
open 127.0.0.1
- type:
you should see something like this:
NOTE: if the desktop game match ended, just start a new match. you might have to restart the whole server and client executable(s) -- so use multiple command prompts/terminals and use the
up
arrow to re-run the same command (or use the handy shortcut, alias, script, as recommended).
let us take a look at a common issue with web browser games. data size downloads are quite sensitive to many users. keeping them small while trying to keep up visual quality up is a delicate balance.
for the purpose of this HowTo, we are going to reduce the texture sizes for EVERYTHING for HTML5.
- Menu bar -> Window -> Developer Tools -> Device Profiles
- in the Device Profiles -> Existing Device Profiles window
- select the
HTML5 ...
(3 small "dots") - or the HTML5
Texture LODGroup
(wrench icon)
- select the
- this will bring up the HTML5 Device Profile settings window
- set ALL
Max LOD Size
to 256 (to start)
- set ALL
- in the Device Profiles -> Existing Device Profiles window
- here, we see the
World
limit set to256
- do the same for ALL the other categories
doing this will greatly reduce the <project>.data
file size
- repackage and notice the difference in the
data
file size
back in the first HowTo: PIE was mentioned. here's a link that will explain this feature in better details:
NOTE: for HTML5, set the Editor's previewer to the following to see (as close as possible) for the following equivalent HTML5 rendering format:
- ES2: WebGL1
- ES3: WebGL2
- ES3.1: WebGL2 + WebGPU (someday...)
Next, Debugging UE4 HTML5