- Home /
UNET: Is it possible to use the same scene for online and offline play? (without disabling my NetworkIdentity objects)
If I have a scene that is shared between online and offline games, it works fine for when the game is online (because the server activates the disabled NetworkIdentity objects). However, once I load this scene offline, all the GameObjects that contain NetworkIdentity are disabled. How should I do this? Creating a copy of the scene is just illogical, prone to error and horrible maintenance. Also, lots of my objects are prefabs, so creating copies of prefabs for offline play makes even less sense.
Wondering the same thing, have you come to a solution yet?
Answer by seanr · Nov 12, 2015 at 01:26 PM
For "offline" mode, you can just run the game as a host with no clients.
Answer by jankrib · Apr 07, 2018 at 07:41 AM
I know this is an old question, but this is something I always struggle with. I managed to get a decent setup now where I do as @seanr suggests and create a host when running offline.
Still, I couldn't run scenes for debugging without going through the main menu of the game because unity would disable all my game objects with a NetworkIdentity. My solution was to create a PostProcessor for the scene. This creates a dummy NetworkManager if there is not one already.
public class MyScenePostprocessor
{
[PostProcessSceneAttribute(2)]
public static void OnPostprocessScene()
{
if (!Debug.isDebugBuild)
return;
var networkManager = Object.FindObjectOfType<NetworkManager>();
if (networkManager == null)
{
networkManager = new GameObject("DummyNetwork").AddComponent<NetworkManager>();
networkManager.playerPrefab = Resources.Load<GameObject>("Player");
networkManager.StartHost();
}
}
}
I used your solution and I works sofar that it spawns the playerPrefab. But still all my NetworkIdentity objects that are part of the scene are beeing disabled and I can't get them to be activated