0

Just like the title, in Unity 2023.1.0a19, I created a new project, then installed the newest version of Cinemachine 2.9.5 by Package Manager, and it got 3 errors:

Errors

Library\PackageCache\com.unity.cinemachine@2.9.5\Runtime\Core\CinemachineVirtualCameraBase.cs(817,29): error CS0103: The name 'FindObjectsByType' does not exist in the current context
Library\PackageCache\com.unity.cinemachine@2.9.5\Runtime\Core\CinemachineVirtualCameraBase.cs(818,22): error CS0103: The name 'FindObjectsInactive' does not exist in the current context
Library\PackageCache\com.unity.cinemachine@2.9.5\Runtime\Core\CinemachineVirtualCameraBase.cs(818,51): error CS0103: The name 'FindObjectsSortMode' does not exist in the current context

This is the source code:

#if UNITY_EDITOR
        [UnityEditor.InitializeOnLoad]
        class OnDomainReload 
        { 
            static OnDomainReload() 
            {
#if UNITY_2023_1_OR_NEWER
                var vcams = FindObjectsByType<CinemachineVirtualCameraBase>
                    (FindObjectsInactive.Include, FindObjectsSortMode.None);
#elif UNITY_2020_1_OR_NEWER
                var vcams = FindObjectsOfType<CinemachineVirtualCameraBase>(true);
#else
                var vcams = FindObjectsOfType<CinemachineVirtualCameraBase>();
#endif
                foreach (var vcam in vcams)
                    vcam.InvalidateCachedTargets();
            }
        }
#endif

Bugs appear at line 8~9. Similarly, other bugs in same code file

if (cam == null)
#if UNITY_2023_1_OR_NEWER
                cam = Object.FindFirstObjectByType<Camera>(FindObjectsInactive.Exclude);
#else
                cam = Object.FindObjectOfType<Camera>();
#endif

Error report:

Library\PackageCache\com.unity.cinemachine@2.9.5\Editor\Menus\CinemachineMenu.cs(267,30): error CS0117: 'Object' does not contain a definition for 'FindFirstObjectByType'

I attempted to change the code like

#if UNITY_EDITOR
        [UnityEditor.InitializeOnLoad]
        class OnDomainReload 
        { 
            static OnDomainReload() 
            {
                var vcams = FindObjectsOfType<CinemachineVirtualCameraBase>();
                foreach (var vcam in vcams)
                    vcam.InvalidateCachedTargets();
            }
        }
#endif

Well, the bugs seems be fixed, and it told me

The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.unity.cinemachine/Editor/Menus/CinemachineMenu.cs and changed back.

I tried it at Unity2019.4.21, but the similar problem appear again. I'll start new program at Unity2023, so I should fix the problem in this version first, hope anyone can help me.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

It was fixed automatically by upgrading Unity version to 2023.1.0a21. Anyway, the Alpha version is still unstable