-
-
Notifications
You must be signed in to change notification settings - Fork 305
Offline Mode
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.
So if you think about it, single player could very well be a server that has the following attributes:
- Does not register with a master server
- Does not register with a nat traversal server
- Does not accept any connections (max players is 0)
- 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);
((UDPServer)server).Connect();
// Block all connections to skip the validation phase
((IServer)server).StopAcceptingConnections();
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)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow