# Unity 5.3.1: Single player is broken

In Unity I converted my single player game to a multiplayer game. Now, the single player game does not work anymore because the objects are disappearing on start, due to the network identity.

What is the best practice for still using the same objects in a single player game?

My question is about a general implementation, and not about something in my game specific.

Example:

We create a simple single player game:

• Make a sphere
• Make a script to move it with arrows

We have a single player game!!

• Change the script to be a networkbehaviour
• Check for islocalplayer in the script
• Make the sphere a network identity
• Make a network controller

Now we have a multiplayer "game"!

HOWEVER

If we now want to play this game singleplayer, it will not work. Just try adding the sphere to a scene. It will disappear on start.

What can I do to make the object usable in both single and multiplayer scenes?

• We're going to need a lot more details about how you're managing your objects & networking in single-player to be able to help you debug this. Can you include some relevant code? Ideally a minimal sample that demonstrates the problem. Feb 24 '16 at 13:14
• There is not enough information to provide you with any type of answer that would be useful to you. What is wrong with the network identity? Are you providing a unique ID for each object? Can you provide some code/screenshots of what you have tried? Feb 24 '16 at 13:24
• Thank you for taking an interest! I have edited my question. I hope it is a bit more clear. If it is not, just ask :) Feb 24 '16 at 14:17

You may be overthinking it. Perhaps you can simply start your game as a host and not allow any additional connected players.

The NetworkManager enables your game to have multiple clients. It does not require you to. Trying to build a second version of your game for single players is often needless effort.

• This is actually the solution I went with. Added a script that does "GetComponent<NetworkManager>().StartHost();" on start() method. Mar 2 '16 at 9:21
• Do you know if it will still popup the windows firewall notification, and if there is a way to disable this for singleplayer games that i host like this? I don't want to spook the players Mar 2 '16 at 9:21

For an online Multi player game, we take pong game as example.

The MVC pattern is a good solution here. You would need three different controllers:

• The LocalPlayerController which is sending commands to a paddle by listening to the local input devices. If you have multiple input devices (keyboard, mouse, gamepad...) it might be a good idea to further subclass it into the one it listens to. In any case, these class(es) should be used in both singleplayer and multiplayer, because it makes no difference for the control who you are playing against.
• The AIController which analyzes the current game state and sends commands to an ai-controlled paddle.
• The RemotePlayerController which listens to a network socket and interprets the incomming messages as commands to a paddle.

Regarding network output: This would not be another Controller, this would be another View. A view is not just something you see on the screen. It is any form of output representation of the model (the model in the context of game development would be the game state). It can be a graphical output on the screen or a data stream sent over the network. In this case the NetworkView would observe any paddles controlled by LocalPlayerControllers or AIControllers and translate their movement to the network.

• Link-only answers are discouraged here. This answer would be better if you included a summary of the key points found at the link, so that it remains a useful signpost even if the linked resource later becomes unavailable. Feb 25 '16 at 12:50
• Thank you for your answer Manoj. I think I understand what you mean, but I am not sure how this will translate to a practical Unity example. Could you maybe explain that? Feb 26 '16 at 8:45
• Also: what do you mean with paddle? Feb 26 '16 at 8:45
• @Tsuyosa paddle means your player. assume pong game as example. For an online multiplayer game you have to manage 3 things mainly. 1. Local Player, 2. AI, 3. Remote Player. the thing explained above is based on this only Feb 26 '16 at 10:00
• Thank you for your answer, but it does not really answer my question. Unity already handles things like this for me. My question is about using the same object for both single player and multiplayer games, inside the Unity framework. This does not answer that. Feb 27 '16 at 13:26