Online vs. Offline Data

I’m currently working on a game that can be played online or offline, and I’d like to support simple drop-in, drop-out multiplayer that doesn’t require a new game to be started. For example you can have a player join in the middle of the game, and then leave later on without requiring a restart. In the past, I’ve always done this by having an “offline” variable, and then a “networked” version of that variable that gets synced. For example I might have “_currentState”, and “_netCurrentState”, with a function that writes to whichever is needed.

However, this is always an error prone approach, and I inevitably spend time tracking down bugs that result from essentially having 2 copies of the same data. To make this simple, I’d like to basically use NetworkVariable for both offline and online, and just have these get initialized when switching to online mode. However, when I do this and play the game in offline mode, I’m getting a lot of warnings and errors that have to do with the network game not running.

Has anyone found a good solution to this problem?

Hi @moose0847 , the approach I follow in this case is to make your “Host” mode your singleplayer mode.

This means that your game instance would be both the server and the client when playing single player.

Does this help?

Yes this helps! I’ve just decided to make the game inherently networked, even if it’s just a local game.

1 Like