Author Topic: How to structure project for both multi/single-player?  (Read 2487 times)


  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
How to structure project for both multi/single-player?
« on: June 03, 2013, 01:33:51 PM »

I just bought TNet and I wonder how to structure my project (on a macro level). I'd like to structure my code in a way that allows game play modes similar to Diablo II: a off-line mode with local save game files + local split-screen multiplayer (two players on the same keyboard) + local LAN multi-player aka. Open BattleNet. A online mode with save game files on a remote server, leaderboards + (nice-to-have) online multi-player where people can use the online save files aka. Closed BattleNet.

Now, how does TNet fit in? Obviously, I'd like to re-use as much code and assets as I can. In my game I got the usual stuff: space ships, planets, projectiles, particles etc.

Do I need two variants of my assets? One for local stuff (without anything TNet-related) and one for everything else? Or do I need three (offline, local multiplayer, internet multiplayer)? Or do I need only one variant? Where let's say a spaceship is full of components which I SetActive(true/false) on behalf?

Yeah I know it's hard to discuss high-level stuff on a forum. I bought the Space Game Starter Kit because I thought it would be an answer to my questions, but it seems the scope of the SGSK is a lot smaller.
#301224014, #301432336, #302399130


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to structure project for both multi/single-player?
« Reply #1 on: June 03, 2013, 09:32:35 PM »
SGSK wouldn't be a very good "starter kit" if it was advanced as it would go over people's heads :)

With TNet you can keep the same code for both single and multiplayer. Calling tno.Send with the target of "all" will automatically echo the packet locally if you are playing offline, for example. You can start a local server and connect to yourself from within Unity, and then your saved state can be managed by TNet as well by simply using a saved target type (Target.AllSaved for example) -- assuming you specified 'true' for the 'persistent' flag when joining a channel. This basically gives you an ability to save your game for free if everything goes through RFCs.

In general your question is a bit on the high-level side, so it's hard to give specific advice.