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

Question a Native way to detect if system is running in Client or Server World ?

Discussion in 'NetCode for ECS' started by Opeth001, Jul 14, 2022.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,078
    Hello everyone,

    im in a case where some mixed systems (running in both server and client worlds) need to check if the current world is client or server to change some behaviors.
    these systems should be defined once for both worlds to maximize code sharing and minimize simulation divergence, but in some cases certain components should be ignored in the server world and vice versa.

    sadly this Client/Server words separation approach makes it impossible to use scripting define symbols.

    I know there are several ways to do it like:
    * create client/server singleton components and check if these singletons exist to determine the current world.
    * Just check the current world name.


    but I am asking here if a native way is already predefined by the Netcode package.

    Thanks
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    804
    in 0.51 you an alsocheck something like
    Code (csharp):
    1.  
    2. var isServer = world.GetExistingSystem<ServerSimulationSystemGroup>() != null;
    3. //for clients ca be either
    4. var isClient = world.GetExistingSystem<ServerSimulationSystemGroup>() == null;
    5. var isClient = world.GetExistingSystem<ClientSimulationSystemGroup>() != null;
    6.  
    if 1.0 we have a completely native and different way to discern that (more easy and straightforward). But for now you have to stick with this.
     
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,266
    What's the new way to distinguish between server and client in a system, now that 1.0 is out?
     
  4. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    265
    Marble likes this.