using NetworkBehaviour vs MonoBehaviour advantages?

So I’m still learning to work with the whole new UNET stuff. I’ve been converting a singleplayer sidescrolling 2D game to a multiplayer version of it.

Now in this project I have a 2D character controller, similar like the PlatformerCharacter2D and Platformer2DUserControl you can find in the 2D Standard Assets.

My first approach was to make the UserControl script a networkbehaviour, add a NetworkIdentity to the GameObject and then add several isLocalPlayer checks on the right places in the UserControl script.

Now, the problem now is ofcourse that my UserControl script isn’t useable anymore for the singleplayer version of the game, unless you start a multiplayer game with just one player.

So now I’m using a different approach based on the following assumptions:

  • when the script is used as a singleplayer script, I can ignore or remove the NetworkIdentity.
  • when the script is used as a multiplayer script, there is (or should be) a NetworkIdentity. I can use this NetworkIdentity to check for the isLocalPlayer variable.

So far the only advantage of using a NetworkBehaviour in this case was that I could directly check the isLocalPlayer variable. In this script, I don’t use any Commands or client-server-client communication. So am I right in assuming that I can just use MonoBehaviour for this case?

I would say it is easier to think of singleplayer as “multiplayer with just one player”. You don’t have to program two different behaviours that way.

1 Like