Search Unity

Question Need help regarding to multi platform multi VR device development

Discussion in 'AR/VR (XR) Discussion' started by mobfish_cai, Aug 17, 2020.

  1. mobfish_cai

    mobfish_cai

    Joined:
    May 3, 2018
    Posts:
    23
    I asked part of the question in other forum area, but so far nobody sees my post (as always)

    https://forum.unity.com/threads/how-is-the-package-manager-handled-in-cloud-build.951639/

    The gol I'm trying to re-achieve (in EVERY Unity Big Update):

    - Resolve conflict between plugins, this time, packages.
    - Remove/ignore unnecessary assets/scripts/folders in different builds.

    The issue I encountered:

    - Unity Package assets and scripts can't be modified
    - Some packages, in this case, VR packages, contains aar files, that will prevent app from successfully build. and for example I build for Oculus platform, then the aar files and other assets in WaveVR (for Vive Focus VR) package will also be included. This is not what I want.
    - Unity doesn't provide any solution to exclude package or asset folder during build, we have to write on our own.
    - Just because we write on our own, there will be a serious issue with script not found error, which should be actually no problem since we don't use these in this specifc build, however, it causes issue on Unity XR Management:

    E/Unity: A scripted object (probably UnityEditor.XR.Management.XRGeneralSettingsPerBuildTarget?) has a different serialization layout when loading. (Read 52 bytes but expected 108 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

    I believe It's because some vr loader scripts doesn't exist and the whole XRGeneralSettingsPerBuildTarget can't be loaded.

    The result is, Unity is trying to encourage multi-platform xr development but it totally failed on my side, and I already took a lot of time on it to build workaround. And I need it in cloud build too, which I haven't tried because local build always fail on device.

    So far I've tried these solutions:

    - Click a menu item before build, to change what packages can be load or removed. And perform build after that. However, after change packages, Plugin Provider Setting become "weird", I can't select the provider which is just added during the process. The checkmark is always not checked, and VR mode doesn't start when build to device.
    - Change packages in IPreprocessBuildWithReport, it doesn't have setting issue in Unity Editor, but due to the error "A scripted object (probably UnityEditor.XR.Management.XRGeneralSettingsPerBuildTarget?) has a different serialization layout when loading", VR can't be started automatically.

    I'm trying a third solution, idea is ignore XRGeneralSettings, and use XRManagerSettings and XRLoader directly in Runtime, and ignore everything in "XRGeneralSettingsPerBuildTarget" and the default assets, except loader and settings.

    I want to ask if there are any other straightforward ways to do this.
     
  2. linojon

    linojon

    Joined:
    Aug 25, 2014
    Posts:
    118
    The BridgeXR package (on the Asset Store) does this for Project Assets, components and prefabs
     
  3. mobfish_cai

    mobfish_cai

    Joined:
    May 3, 2018
    Posts:
    23
    I finally have a complete solution, which cost me this whole week. I'll post it here in case someone need it. This is ONLY for Unity 2019.4.

    - When submit project to git, all potencial used packages must be added to package manifest. Otherwise, even a scriptableobject script is added later on, this "Object" can still not be loaded with AssetDatabase class. This goes for both XRLoader and related XR Settings.
    - Be sure to disable "Initialize XR on Startup".
    - All XR Settings should be included in Preloaded Assets in player setting.
    - If build in Cloud Build, package add or remove process should be performed BEFORE IPreprocessBuildWithReport. Pre build script can be used to perform this. However, just as I said, if a script is not included at the beginning of cloud build check out, the corresponding scriptable object will be gone, forever, like it doesn't even exist.
    - If build in local, package add or remove process can be ignored for 2 reasons:
    - 1. if this process is performed during IPreprocessBuildWithReport, there is a chance that build will fail with Visual C# compiler error (not 100% and don't ask me why).
    - 2. If this process is performed in custom menu button, there before each git commit this have to be restored. Which complicate things in my case.
    In order to make local build success, further action is requried.
    - If build in local, for Android, IPostGenerateGradleAndroidProject has to be used to solve some gradle or manifest conflict. In my case, android manifest is already set correctly before build, so I don't touch this file in this step. Here 2 actions are performed:
    - delete the aar entries in build.gradle,
    - delete ".so library" files in "[gradle-output-path]/src/main/jniLibs".
    Action 1 is to prevent some weird gradle conflict or manifest conflict, Action 2 is to prevent some plugins from using itself or loading itself which cause issue (in my case, Wave XR Plugin for Vive Focus). These Actions are not needed in Cloud Build because they're excluded in pre build script.
    - If there are any local assets or sdks needs to be excluded, it should be done in IPreprocessBuildWithReport instead of pre build script, by change "FolderName" to "FolderName~", and it should be changed back in IPostprocessBuildWithReport to prevent compiler error
    - XR Plug-in Management Settings are f***ed up either way, because "serialization doesn't match" or something (I forget the word in log) due to package change. So, a individual solution is needed to host current actual XR Loader. I wrote a new ScriptableObject for this and store ONLY one XRLoader, and put this asset instance in Resources folder. This asset is properly set before IPreprocessBuildWithReport, in my case, menu button for local build, and pre build script for cloud build. In runtime, load this asset using Resources.Load, and instantiate a new
    XRManagerSettings for the usage.
     
    Last edited: Aug 21, 2020
    tenconmar likes this.
  4. mobfish_cai

    mobfish_cai

    Joined:
    May 3, 2018
    Posts:
    23
    Also, BridgeXR is for old vr implementation, what I need is for the new xr management. But thanks anyway.
     
  5. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    29
  6. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    189
    All of this is for legacy XR systems at this point. Generally going forward you should be able to build for any platforms using OpenXR.
     
    tenconmar likes this.