Skip to content

Offline Mode

Peter Halasz edited this page Jul 16, 2019 · 4 revisions

Something you may be curious about is how you can make your game both single player and multi-player. Your main problem is probably going to be trying to figure out how you can separate all your RPC calls and your offline direct calls. The thing that may surprise you is if we were to say that there is no need for the distinction between "Online" and "Offline" code.

The Solo Server

So if you think about it, single player could very well be a server that has the following attributes:

  1. Does not register with a master server
  2. Does not register with a nat traversal server
  3. Does not accept any connections (max players is 0)
  4. Blocks any other connection attempts

Well this makes sense so far, if a server doesn't accept any clients then technically it is nothing more than an offline game. However, what about the RPC calls and the various other networked things like the networkObject? Well, the answer is simple, Forge Networking was built to where the server isolation is offline play. If there are no connections to the server, it will call all RPCs directly without any network layer involved for sending (it doesn't send to itself, just runs the method locally). Below is an example of a server put into an offline like state:

// Zero connections allowed to this server
NetWorker server = new UDPServer(0);

// Block all connections to skip the validation phase


When you specify receivers that do not include the server, such as Receivers.Others then the server will not call the method, even with no other connections.

Your code will still need to initialize the NetworkManager just as you would when doing online mode. The only difference between the two modes is that offline will not accept any connections, and your server will be your "singleplayer" instance.


Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Web Server
Netcoding Design Patterns
Clone this wiki locally
You can’t perform that action at this time.