Search Unity

Issue with WebGL builds within VR/Oculus project

Discussion in 'VR' started by Kamalen, Jan 19, 2020.

  1. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    Hi,

    I have a project I intend to have two clients ; a VR client and a WebGL client. I am using the Oculus Integration package as well to build to Oculus Quest.

    While everything runs correctly in Android, when I try to build the project in WebGL, I have an error concerning the Microphone class.

    When stubbing it, build work but the WebGL player cause the following error :
    "To use dlopen, you need to use Emscripten's linking support"

    This error looks to be caused by Oculus Integration, because when removed, the player works successfuly.

    Is there a way to make WebGL and Oculus Integration work in the same project ? There is very few things different between clients, so I'd rather not having separate projects, because sharing code is such a chore in Unity.

    Thanks !
     
  2. Thronost

    Thronost

    Joined:
    Nov 25, 2016
    Posts:
    2
    Hi, I'm having the same problem.
    Did you ever found a solution?
     
  3. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    I eventually worked around by making actually two separated projects ; a WebGL and a Oculus. My assets got on both projects using a folder with logical links, and only the Oculus project had the Oculus integration & Unity XR packages.

    For the few of my scripts depending on XR, I used #if UNITY_WEBGL to comment them out.

    If you want more details, feel free to ask. :)
     
    LKSim likes this.
  4. mafima

    mafima

    Joined:
    Jun 17, 2016
    Posts:
    6
    You can also create an Assembly definition to skip the Oculus scripts for the WEBGL build to fix the error.

    upload_2020-11-30_10-12-50.png
     
    DevDunk and CrispyCritter like this.
  5. CrispyCritter

    CrispyCritter

    Joined:
    May 11, 2018
    Posts:
    19
    have you tried this? i have had no luck :(
     
  6. anthodb

    anthodb

    Joined:
    Sep 6, 2012
    Posts:
    20
    Anybody has tested this process with Assembly definition? Didn't find the right config.. The solution with logical link does seem acceptable but this would be much cleaner with assembly.
     
  7. dhruv_unity154

    dhruv_unity154

    Joined:
    Feb 11, 2022
    Posts:
    14
    Have you tried WebGL build in the same VR/Oculus project? I am working on a multiplayer project which has Oculus Integration and PUN as resources. The project needs to be on two platforms: Oculus and WebGL. When I am going to build WebGL, the build is successful(after some changes script code commented execution for WebGL).

    But when i am trying to run it gives an error : ("To use dlopen, you need to use Emscripten's linking
     
    Last edited: Mar 7, 2022
  8. Max_Aigner

    Max_Aigner

    Joined:
    May 9, 2017
    Posts:
    42
    Adding an Assembly reference is a great Idea and a lot better than removing the whole package at every WebGl build or having two projects I think.

    So in general: With Assembly references you can control if the code will exist in certain plattforms. You can exclude all the code that is in the same folder as the Assembly Reference Asset File and all subfolders (that don't have an Assembly Reference File themselves) by ticking the checkboxes of your Assembly file. This is exactly what we need here (exclude Oculus files when we build for WebGL)

    In 2022 it seems this process has changed a bit. I had to do the following:

    First of all we want to find all the Assembly Definition files of our Oculus Plugin and tick the "WebGL" checkbox in the "Exclude Platforms" list.
    Oculus added a couple of Assembly Definition files in their latest version and those files are all hidden in the subfolders of the "Assets\Oculus" folder. For example this one is in the folder "Assets\Oculus\AudioManager:

    upload_2022-6-2_8-27-26.png

    1. In order to find all of those Assembly files, I was using a simple windows search for "*.asmdef" in the Asset\Oculus folder.
    So let's open the Oculus folder by opening it like so: (2021.3.2f1).
    upload_2022-6-2_8-30-36.png
    3. Enter "*.asmdef" into your windows file search bar to find all Assembly Definitions that are now included in the current Oculus Plugin and therefore exist in the "Oculus" Folder just like this:
    upload_2022-6-2_8-32-53.png
    Keep in mind to ONLY Exclude those Assembly Definitions from WebGL, that are NOT Editor Assemblies (if the word Editor is in them, then don't edit them).

    Last but not least, create an Assembly Definition File directly in your Oculus Folder, call it
    "Oculus.All" and include ONLY the Editor. As in the main level there will only be Editor Scripts. Then add those three necessary Assemblies to that Assemblydefinition that will be needed:
    • Unity.TextMeshPro
    • Oculus.VR and
    • Oculus.Platform.
    It should look like so: (in the image I have some more assemblies added but they are not needed, I just forgot to put them out again):
    upload_2022-6-2_8-25-5.png


    Now your webgl build should work like a charm. cheers.

    remember to like this post if you liked it. thank you
     

    Attached Files:

    Last edited: Sep 23, 2022
  9. omegletvcam

    omegletvcam

    Joined:
    May 26, 2022
    Posts:
    1
    I am working on a project where I plan to build two clients : a VR client as well as an WebGL client. I use the Oculus Integration program to create Oculus Quest.

    Although everything works fine in Android however, when I attempt to build the application in WebGL I get an error with microphone.

    If you stub it, build works, but the WebGL player will give the following error "To use dlopen, you need to use Emscripten's linking support"

    The error appears to be due to Oculus Integration, because when removed, the player functions successfully.omegletv.

    Is there a way to have WebGL as well as Oculus Integration work together in the same project? There are very few aspects that are different between the two clients, and I'd prefer not to have separate projects because sharing code can be a hassle in Unity.

    Thanks !
     
  10. Max_Aigner

    Max_Aigner

    Joined:
    May 9, 2017
    Posts:
    42

    Hi omegletvcam..
    I am currently working on a project that has to be built for both Oculus and WebGL. You have to do some tweaks in order to get it to work for both platforms.

    The Oculus SDK uses that Microphone which causes WebGL to not work. In the very post above your post, I have described in a detailed way, how you can track down and exclude the Oculus SDK's Assembly Definitions, so that they get excluded from your WebGL Build. Do that and the WebGL Microphone Errors will disappear.


    There is more to be done however.

    On some occasions you will have to exclude code from being built for the one or the other plattform with compilerdirectives like this:
    #if !UNITY_WEBGL
    #endif
    like this:
    upload_2022-6-2_8-8-12.png

    Also In order to upload your APK Android Build to the Oculus Store you will have to remove the Microphone permit with your own custom Manifest. Otherwise you will not be allowed to publish your APK to the Oculus Store - uploading for the Alpha/ Beta Channel will work, but not publishing it to the open world.

    upload_2022-6-2_7-58-45.png

    Here is my version of the AndroidManifest. As soon as you tick the "Custom Main Manifest" checkbox, it will create some AndroidManifest in the given folder (Assets\Plugins\Android\AndroidManifest.xml) and you can edit it with the following:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.unity3d.player"
    5.     xmlns:tools="http://schemas.android.com/tools">
    6.     <!-- Request the headset DoF mode -->
    7.     <uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="true" />
    8.     <uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove" />
    9.     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" tools:node="remove" />
    10.     <application>
    11.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    12.                   android:theme="@style/UnityThemeSelector">
    13.             <intent-filter>
    14.                 <action android:name="android.intent.action.MAIN" />
    15.                 <category android:name="com.oculus.intent.category.VR" />
    16.                 <category android:name="android.intent.category.LAUNCHER" />
    17.             </intent-filter>
    18.             <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    19.             <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
    20.             <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
    21.             <meta-data android:name="com.oculus.supportedDevices" android:value="quest|quest2" />
    22.             <meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
    23.         </activity>
    24.     </application>
    25. </manifest>
    26.  
    Also keep in mind, that you might want some post processing Effects on webgl but NOT on your oculus build (probably).

    If that helped you, I would appreciate a "Like" :)
     
    PrimePeter and LKSim like this.
  11. Mateofloyd

    Mateofloyd

    Joined:
    Sep 6, 2019
    Posts:
    3
     
    PrimePeter likes this.