Search Unity

How to test a VR multiplayer game

Discussion in 'VR' started by eron82, Sep 24, 2018.

  1. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    83
    I cannot run two instances of the game (1 standalone and 1 in the editor) because one of them is automatically closed when the other is active. How can i test a multiplayer game with one vr device on the same computer? Thanks
     
  2. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    Make a non VR player for your game so you can use it with your keyboard while testing. Last time I tried that few month ago it worked. Hopefully this is still possible.
     
  3. Mariiooo

    Mariiooo

    Joined:
    Sep 4, 2019
    Posts:
    6
    Did you manage to do it? I'm working right now on a VR Multiplayer App with the Unity MLAPI (Unity Multiplayer Networking) And I'm looking for something to test my multiplayer VR app.
     
  4. mes007

    mes007

    Joined:
    Apr 1, 2019
    Posts:
    4
    Same, Did you succeeded ?
     
  5. qhenckel

    qhenckel

    Joined:
    Apr 23, 2015
    Posts:
    1
    I am also working with the Unity.Netcode package in VR. I found this tool: https://github.com/VeriorPies/ParrelSync but that just allows you to get out of building the game before each test. I am also using the valve.vr library instead of openxr and it seems to have some desktop debug ability, but unity tends to crash when two editors are trying to use the headset.

    The issue really comes down to isolating once instance from the headset, since this causes to instability. I'll report back if I find away.
     
  6. imbeyondboredom

    imbeyondboredom

    Joined:
    Jun 25, 2022
    Posts:
    1
    I know this is resurrecting an old thread but I'm able to do this now with steps outlined in this github issue and I don't see anything else on the internet where this problem is discussed or solved:
    https://github.com/VeriorPies/ParrelSync/issues/77

    Basically you just need to disable VR on startup:
    [Edit]->[Project Settings] -> [XR Plug-in Management] -> Select the desktop tab -> Uncheck "Initialize XR on Startup"

    Then use ParrelSync APIs to only turn VR on in the main game. Here is my code which is formed off of the code in that issue but set up to automatically run if it's in a clone
    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR
    3. using UnityEngine;
    4. using ParrelSync;
    5. using System.Collections;
    6. using UnityEngine;
    7. using UnityEngine.XR.Management;
    8.  
    9. public class VRUtilities : MonoBehaviour
    10. {
    11.  
    12.     void Awake()
    13.     {
    14.         if (ClonesManager.IsClone())
    15.         {
    16.             DisableXR();
    17.         }
    18.         else
    19.         {
    20.             EnableXR();
    21.         }
    22.     }
    23.  
    24.     public void EnableXR()
    25.     {
    26.         StartCoroutine(StartXRCoroutine());
    27.     }
    28.  
    29.     public void DisableXR()
    30.     {
    31.         StartCoroutine(StopXRCoroutine());
    32.     }
    33.  
    34.     public IEnumerator StopXRCoroutine()
    35.     {
    36.         Debug.Log("Stopping XR...");
    37.         XRGeneralSettings.Instance.Manager.StopSubsystems();
    38.         XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    39.         Debug.Log("XR stopped completely.");
    40.     }
    41.  
    42.  
    43.     public IEnumerator StartXRCoroutine()
    44.     {
    45.         Debug.Log("Initializing XR...");
    46.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    47.  
    48.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    49.         {
    50.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    51.         }
    52.         else
    53.         {
    54.             Debug.Log("Starting XR...");
    55.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    56.         }
    57.     }
    58. }
    59. #endif
    60.  
     
    ronjart likes this.
  7. Esteban-Gallardo

    Esteban-Gallardo

    Joined:
    Feb 19, 2013
    Posts:
    47
    Testing 2 players in VR at the same time in the same computer is impossible as far as I know. What VR programmers usually do is two run 2 Unity Editor instances one with a VR client and another with the desktop client.

    I made a lesson related to multiplayer in VR as a part of a gamedev bootcamp I did last year. I hope it helps:

     
  8. Jamesgf_4322hn

    Jamesgf_4322hn

    Joined:
    Sep 14, 2022
    Posts:
    6
    and what to do with the image delay, I don’t know about my opponents, but in my shooter the image slows down for 1-1.5 seconds, which significantly interferes with the game, I would like to somehow speed up this process, or will I have to change the console ?!
     
  9. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    101
    Thank you, this has worked great for me.
    (removed the duplicate "using UnityEngine" and added a "yield return null" at line 40)
     
  10. nilagard

    nilagard

    Joined:
    Jan 13, 2017
    Posts:
    77
    Just to clarify your issue and give you an answer from a smoothbrain. As far as I know it cannot be done. Your computer can simulate two instances using the same computer (Tarodev on youtube has a great example on this) But you cannot simulate two VR headsets, as the computer only has access to one. There is no software to duplicate two instances of this because it's just not common enough for it to be a problem. To test VR multiplayer you either need A) friend with VR which has some free time. B) Two headsets, one a standalone like a Quest2(or 2), and one which you can hook up to your computer.