Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Singleplayer mode implementation usage of networkvariables

Discussion in 'Netcode for GameObjects' started by miccalisto, Apr 19, 2023.

  1. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    So I want my game to have both singleplayer and multiplayer modes. If I use NetworkVariables and RPCs for my multiplayer part will I be able to use those same variables for singleplayer without the need to start a server?

    For example I have one networkvariable that stores a value and is modified somehow, but I need it to be modified the same way both in single and multiplayer modes.

    Can I use this variable for singleplayer? Or do I have to have 2 sets of variables for everything one being normal and the other networking variable and just checking whether the mode is singleplayer or multiplayer to decide which to use?
    Or how do you solve this problem of having both singleplayer and multiplayer modes?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,336
    They should work the same provided that you follow the general recommendation of implementing singleplayer as “host playing alone”.
     
    RikuTheFuffs-U likes this.
  3. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    432
    No, you'll need to start the game in Host mode. if you start the game in Host mode, your machine will be both the client and the server, and everything will work as usual without any oher change from your side.