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. Dismiss Notice

Resolved Is it possible to disable Netcode (Client/Server Worlds) for a Scene?

Discussion in 'NetCode for ECS' started by Jonathan_L, Sep 14, 2023.

  1. Jonathan_L

    Jonathan_L

    Joined:
    Jan 26, 2016
    Posts:
    38
    Just wondering if it is possible to disable Netcode for a scene, so that instead of creating Client/Server worlds, one Default World is created and netcode does not run at all?

    I wanted to make a simple test scene using physics but I am getting the error: "The default physics world on the client contains a dynamic physics object which is not a ghost. This is not supported, in order to have client-only physics you must setup a custom physics world for it."

    I am seeing info on custom bootstrapping but I wouldn't even know how to approach bootstrapping conditionally based on the scene that is currently being run.
     
  2. Jonathan_L

    Jonathan_L

    Joined:
    Jan 26, 2016
    Posts:
    38
    Was able to get it working with this:

    Code (CSharp):
    1. public class GameBootstrap : ClientServerBootstrap
    2. {
    3.     public override bool Initialize(string defaultWorldName)
    4.     {
    5.         Scene scene = SceneManager.GetActiveScene();
    6.         if (scene.name == "Interact")
    7.         {
    8.             CreateLocalWorld(defaultWorldName); // local, no netcode bootstrap
    9.             return true;
    10.         }
    11.         else
    12.         {
    13.             AutoConnectPort = 7979;
    14.             return base.Initialize(defaultWorldName); // client/server bootstrap
    15.         }
    16.     }
    17. }
    References:
    https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/client-server-worlds.html
    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
     
    NikiWalker likes this.
  3. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    224