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 Can Netcode for GameObjects Enable Communication Across Different Scenes and Programs

Discussion in 'Multiplayer' started by eda-vfx, Sep 7, 2023.

  1. eda-vfx

    eda-vfx

    Joined:
    May 28, 2018
    Posts:
    4
    Can Netcode for GameObjects facilitate communication between different scenes or programs?

    My requirement is as follows:
    I have two programs, one serving as the controller and the other as the game client. The controller is responsible for sending messages to the game client, indicating actions such as starting the game or selecting difficulty levels. The game client also needs to send back relevant game state information to the controller. However, these two programs will be developed by different individuals.

    In my current testing, I created two different scenes, one for the host and one for the client, within the same project. When the client uses Netcode to connect to the host, the client scene is forcibly switched to the host scene. Can Netcode for GameObjects fulfill my requirements?Thanks
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Yes, but only on the Unity Transport level.

    You can use the higher level NGO features and allow clients on different scenes IF you write your own scene management. Communication with non-Unity apps would still require communicating to them via the transport level which is basically able to send custom UDP packets (like Sockets) as far as I understand it.

    However I'd first check if you really need separate scenes - a scene is often considered a different menu, or game world/level, but that needn't be the case. For instance you could have four different rooms or buildings in the same scene, just spatially separated and perhaps culled to ensure only the one the local player is in will be renderered. The same goes for a fullscreen menu - it could simply be an overlay of the game world, and for performance reasons the world renderers are disabled while the menu is active. Games often use this approach to avoid the scene loading delay/overhead and better management of resources, as the ingame resources will not be unloaded while the menu is shown, making for a snappier experience.

    Alternatively I think you can use both NGO and sockets or a low-level transport separately, provided that both network stacks operate on different ports.
     
    CodeNinja- likes this.