ValveSoftware / steamvr_unity_plugin

SteamVR Unity Plugin - Documentation at: https://valvesoftware.github.io/steamvr_unity_plugin/
BSD 3-Clause "New" or "Revised" License
1.03k stars 256 forks source link

Importing a project in Unity 2020.3 causes SteamVR_Settings to reset #949

Open viliusnbg opened 3 years ago

viliusnbg commented 3 years ago

Hi,

If you have a project that uses SteamVR and you try to import it with Unity 2020.3, the SteamVR_Settings get reset.

A simple usecase where this matters is cloning the project onto a new machine from github. When you clone the project, it needs to be imported into unity and it needs to generate the library folder and all the related settings.

At the end of the import, SteamVR_Settings.instance will be called. This will trigger LoadInstance() which calls Resources.Load("SteamVR_Settings"). Normally, this would load the existing settings, but for whatever reason during project import this will not load anything and return null. Then the default settings will be generated instead and the actual settings file will be overwritten.

This is a big issue as it also happens when automating unity builds, causing a misconfigured build, making automation impossible.

This might be a Unity bug on an intentional behaviour of Resouces.Load(). Regardless there is a workaround:

#if UNITY_EDITOR
            if (_instance == null)
            {
                _instance = UnityEditor.AssetDatabase.LoadAssetAtPath<SteamVR_Settings>("Assets/SteamVR_Resources/Resources/SteamVR_Settings.asset");
            }
#endif

Adding this snippet of code in the SteamVR_Settings.LoadInstance() allows steamvr to still load everything during project import.

Hope this issue can be fixed/worked around in the plugin itself.

zite commented 3 years ago

Thanks for finding this and reporting. That is definitely not what we would expect. I'm going to label this as a unity bug with a workaround as I believe it does not repro on other major versions.

I believe we support moving that file, so I'm not sure doing a load at path is the best plan for the plugin to implement, but is certainly valid on a case by case basis.

Peaj commented 3 years ago

I reproduced the same issue with Unity 2019.4.28f1 LTS and it happens to me in a many other Unity versions as well.

Here is a repo with the repro case: https://github.com/Peaj/SteamVRBug Its a simple project with the latest unitypackage (2.7.3) imported and the legacy VR dialog option accepted. Just cloning and opening it results in a changed SteamVR_Settings file.

This is a major issue. Especially since it leads to resetting "autoEnableVR" to its default value of 1 which in turn leads to a change in the ProjectSettings.

It breaks CI pipelines and means you have to tell everyone to discard their changes after cloning the project.

Peaj commented 3 years ago

I also tested the workaround proposed by @viliusnbg: https://github.com/Peaj/SteamVRBug/tree/workaround It does not work for me as LoadAssetAtPath also returns null.