Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

multiple scenes concurrently runnning

Discussion in 'Multiplayer' started by AnomalusUndrdog, Nov 22, 2009.

  1. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    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. 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, while 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?
     
  2. dbryson

    dbryson

    Joined:
    Nov 9, 2009
    Posts:
    269
    I'm not sure I understand what you want to do. Why would multiple players be playing on the same server if they don't interact with each other (i.e. they are just playing against an AI)?

    I'm new to Unity too, but I don't think it's possible simultaneously.
     
  3. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    I've given a poor example. Not only AI, but there will be player versus player situations too. So collisions in the play session of two particular players should not affect the play session of other players.

    I just hope there's a way to do this.
     
  4. dbryson

    dbryson

    Joined:
    Nov 9, 2009
    Posts:
    269
    First, if you haven't I would suggest checking out the networking information in the manual:

    http://unity3d.com/support/documentation/Components/Network Reference Guide.html

    A common way to do what you want is to build both the client and server into your game app. In single player mode the client simply connects to the local server. In multiplayer mode one person chooses (or is chosen) to host the server and everyone's client connects to that person as the server.

    Otherwise, if you want a dedicated server you would probably have to spawn a separate instance of the server for each game being played.
     
  5. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    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.

    My only problem is how to automate the process of spawning a separate instance of the server every time the user requests a battle, and how does the client know which server instance to automatically connect to.
     
  6. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    Well 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.

    Code (csharp):
    1.  
    2.  
    3. var args : String[];
    4.  
    5. function OnGUI()
    6. {
    7.     for (var arg : String in args)
    8.     {
    9.         GUILayout.Label(arg);
    10.     }
    11.  
    12.     if (GUILayout.Button("Spawn New Instance"))
    13.     {
    14.         var proc = new System.Diagnostics.Process();
    15.         proc.EnableRaisingEvents=false;
    16.         proc.StartInfo.FileName= args[0];
    17.         proc.StartInfo.Arguments = "25006 argument2 argument3";
    18.         proc.Start();
    19.         //proc.WaitForExit();
    20.     }
    21. }
    22.  
    23. function Start()
    24. {
    25.     args = System.Environment.GetCommandLineArgs();
    26. }
    27.  
    28.