Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Offline Hosted mode?

Discussion in 'Netcode for GameObjects' started by BlackBunnyCrankn, Sep 30, 2023.

  1. BlackBunnyCrankn

    BlackBunnyCrankn

    Joined:
    Mar 21, 2020
    Posts:
    21
    What is unitys best practice for offline mode (only 1 player hosting) in a NGO game.

    So I dont know what networking manager and all the other network objects do under the hood. But say we are making a coop\solo player mode. When somebody is playing solo we dont want to waste money using relay or extra compute sending out data for network objects or doing extra work. So what is the best practice for running in Offline mode IE (1 single hosting player)?

    So far all i do is i swap the network transport from relay to unity transport and just host the game. However i havent found anything on running a netcode for game objects solution offline efficiently.
    NetworkManager.Singleton.NetworkConfig.NetworkTransport = unitytransport;
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,576
    Offline play = play as the host, as you do.

    In connection approval all connection requests are denied in offline mode.

    There is no such thing as online vs offline. It's only a matter of disallowing connections. If there aren't any connections and you use the default transport, nothing about that game session is "online".

    Meaning what? Memory? CPU? Bandwidth? Productivity?
     
  3. BlackBunnyCrankn

    BlackBunnyCrankn

    Joined:
    Mar 21, 2020
    Posts:
    21
    Yes, as i am not sure what happens under the hood so even if its just one person in a hosted game i dont know what else can be turned off to increase performance
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,576
    Well if the singleplayer offline mode doesn‘t perform well, the online multiplayer mode will be even worse off. As long as that‘s fine no need to concern yourself with offline play performance. ;)
     
  5. najaa3d

    najaa3d

    Joined:
    Jan 22, 2022
    Posts:
    29
    If it's not the OP's concern, this is our concern. In "offline single-player mode" - we'd like to guarantee there are no connections going through Relay/UGS. It should "just work" -- with no network connections.

    You wrote: "In connection approval all connection requests are denied in offline mode."

    I'm not sure how to interpret that statement.

    Specifically, what do we have to do inside Unity API, to ensure "offline mode / no-connections"??
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,576
    Answered here: https://forum.unity.com/threads/configuring-p2p-direct-through-lan.1500587/#post-9381782

    Relay is an optional service.

    The NetworkManager has a connection approval callback where you can write code that either allows or disallows a client to connect via a boolean. If the game is in locally-hosted offline mode you just deny all connection attempts. That's it.