4

Using the Unity3D engine's high-level networking API (HLAPI) seems to be an all-or-nothing approach. For any game objects expected to be used in multiplayer, (most) behaviors need to be implemented as NetworkBehaviours, and Network components are required. Additionally, a Network Manager is required in all scenes. I'd rather not have duplicate network-enabled versions of all single-player assets, and it seems that the expected practice is for a single-player game to be realized as a LAN Host-based network game with only the single (localhost) client.

My concern is that the HLAPI stuff riding on top of absolutely everything will result in substantial overhead in single-player mode, which is the main focus of the game. Is this a valid concern?

I have considered a couple mitigation techniques, but they pose their own problems for maintainability and code complexity:

  • Prefabs needed in both modes will be duplicated (violates DRY: changes to one prefab need to be manually mirrored in the other)
  • Dynamically modify or replace single-player assets with multiplayer ones, or vice versa (complex and potentially error-prone)

What are some better mitigation techniques? Or are they even needed?

user3071284
  • 6,955
  • 6
  • 43
  • 57
Eric Hughes
  • 831
  • 6
  • 19

1 Answers1

0

This is kind of an old question, but I figure I'd take run at it anyway. Could you detect when you're in single player mode, and in that case use Destroy to remove the components you don't need? For example:

http://answers.unity3d.com/questions/378930/how-delete-or-remove-a-component-of-an-gameobject.html

Bruce Van Horn
  • 613
  • 2
  • 6
  • 14
  • It's unfortunately not a question of just deleting components: `MonoBehaviour`s intended to have network state in the HLAPI (as of the time this question was written) are required to be `NetworkBehaviour`s and work with Network components. Destroy the Network components, and you don't just remove cruft, you also prevent all of your networking-enabled behaviours from working at all. – Eric Hughes Nov 21 '16 at 19:42