x


How to have multiple scenes concurrently runnning

Newbie here. I don't get it. In the online strategy game we're trying to make, the player plays on a certain map against AI opponents or other players. The server is an authoritative server. So the player data, AI objects, the map itself also exist on the server.

The thing is, its an online game, so more than one player plays the game. This means the server needs to administer multiple play sessions concurrently, processing collisions on multiple autonomous maps, making sure collisions on one player's playing session does not affect collisions on another player's playing session.

Is it even possible at all for Unity to administer multiple scenes?

more ▼

asked Nov 23 '09 at 02:33 AM

user-305 (yahoo) gravatar image

user-305 (yahoo)
21 1 1 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Although you can try to get things working with merging all active matches in one scene the best way to go is to startup a headless instance for every match going on. You can start instances of your app in batchmode (headless) using the -batchmode flag.

Search for batchmode in forums give more details how to use it and its limitations (you'll need UnityPro for example).

more ▼

answered Nov 24 '09 at 07:29 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

(comments are locked)
10|3000 characters needed characters left

You can handle multiple scenes. What you're probably looking for is Application.LoadLevelAdditive, which loads a scene without destroying the objects that are currently loaded already. With this, you can load multiple maps simultanuously.

Of course, for a complete solution, things get a little more involved: What I'm doing in Traces of Illumination is laying out the different levels "spatially" so that when I load all of them at once on the server, they don't intersect. That way, multiple game groups (groups of up to 20 players playing one level) can play simultanuously in different levels. To make it possible for different groups of players play in the same level without interfering with each other, I disable collisions between any objects that belong to different groups.

It is kind of complex (you also need to make sure that network messages only get sent to those players for which they are really relevant) but quite doable in Unity.

more ▼

answered Nov 23 '09 at 12:02 PM

jashan gravatar image

jashan
10.1k 25 40 116

(comments are locked)
10|3000 characters needed characters left

I've thought about spawning several instances of the server. That's one way to do it. It would scale well too since it can take advantage of multi-core hardware easily without needing multi-threading.

I managed to create some code that spawns a new instance of the program and pass arguments to it. This only works on standalone builds as webplayers can't receive command line arguments.

var args : String[];

function OnGUI()
{
   for (var arg : String in args)
   {
      GUILayout.Label(arg);
   }

   if (GUILayout.Button("Spawn New Instance"))
   {
      var proc = new System.Diagnostics.Process();
      proc.EnableRaisingEvents = false;
      // args[0] is the filename of the current program
      proc.StartInfo.FileName = args[0];
      proc.StartInfo.Arguments = "25006 argument2 argument3";
      proc.Start();
      //proc.WaitForExit();
   }
}

function Start()
{
   args = System.Environment.GetCommandLineArgs();
}
more ▼

answered Nov 25 '09 at 01:40 AM

user-305 (yahoo) gravatar image

user-305 (yahoo)
21 1 1 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x718
x107
x16

asked: Nov 23 '09 at 02:33 AM

Seen: 5077 times

Last Updated: Apr 12 '11 at 08:03 AM