Errors updating to Cinemachine 2.9.5 on Unity 2021.3.22f1

Hi there,

I’m updating the Cinemachine asset in our project from 2.8.9 to 2.9.5 by going into the manifest.json.

The project is on Unity 2021.3.22f1

Upon re-focusing on Unity, it does its thing, and seems to update the package just fine. However, the moment I select any GameObject with a CinemachineVirtualCamera component and look at the inspector, my console is non-stop flooded with the following errors:

NullReferenceException: Object reference not set to an instance of an object
Cinemachine.Editor.CinemachineSceneToolUtility+<>c.<.cctor>b__21_0 () (at Library/PackageCache/com.unity.cinemachine@2.9.5/Editor/Utility/CinemachineSceneTools.cs:272)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <964670f15c6b47f9b8f9340732720473>:0)

NullReferenceException: Object reference not set to an instance of an object
Cinemachine.Editor.CinemachineSceneToolUtility+<>c.<.cctor>b__21_0 () (at Library/PackageCache/com.unity.cinemachine@2.9.5/Editor/Utility/CinemachineSceneTools.cs:272)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <964670f15c6b47f9b8f9340732720473>:0)

What’s interesting is that if I try to update a branch new project (with the same version of unity) I do not run into this issue. Any ideas?

Some notes:

  • I’m updating to 2.9.5 through the manifest as it seems that 2.9.5 is not an official release of Cinemachine for Unity version 2021.3.22f1
  • I tried going to the Library/PackageCache and completely wiping the folder before re-installing the package. No luck :frowning:

Any help would be greatly appreciated!

Heyyoo

I tried to repro but couldn’t. Do you think you could send us a repro project? What happens if you update through the pack man window? Can you try clearing your library folder close unity and reopen (Backup your project first)?

Let us know

1 Like

Hey Antoine, thank you for the quick reply!

I can’t update through the pack man window as it only shows 2.8.9 as the latest available version for Unity 2021.3.22f1. I see 2.8.9 as the latest version both for my project, and branch new repro projects with the same Unity version (hence why updated by manually changing the manifest.json).

I’ll try clearing the entire library folder and see what happens.

As for repro, I can’t seem to repro this issue in a new project (same unity version), seems to only happen with my current project. If I have to share it, I’ll have to probably downsize the project a bit. Where would I share it?

Hey, I have the same problem. Unity 2021.3.22f1 and the latest version of Cinemachine in the Package Manager is 2.8.9. How do you get 2.9+ into your own project? I also deleted the Library folder, but the highest version is still 2.8.9.

Edit: I think I got it working:

Package Manager → + → Add package by name…

Name: com.unity.cinemachine
Version: 2.9.5

And it seems to work. BUT… I get the following warning inside the package manager:

8965122--1231995--Screenshot 2023-04-21 164430.png

The 2021.3 Unity Manual states that this Cinemachine version is supported:

1 Like

Yes, that is the correct way to install. Unfortunately the 2.8.9 version limit is baked into Unity. We’re working on getting that removed so that you always see the true latest version in package manager. Don’t worry about the not-verified thing, 2.9.5 is compatible.

2 Likes

Just to close this thread up: I got it to work using the following steps:

  1. Close Unity
  2. Wipe the library folder
  3. Edit Packages\manifest.json to update cinemachine entry to 2.9.5
  4. Remove cinemachine entry in packages-lock.json
  5. Open Unity (project will take a while to re-import library)

Thanks for the help!

2 Likes

I get the same console spam errors when selecting a virtual camera in the hierarchy AND when creating a new virtual camera in a scene .

I’ve been seeing this error in 2.9.5 and 2.9.7 for a while and it’s been driving me insane. When I roll back Cinemachine to 2.8.9, the error is no longer present.

The actual solution to remedy this error in 2.9.5 and 2.9.7 is to reset the Unity Editor to the default layout. Crazy, huh?

Can you describe your layout or take a screenshot? Do you have something like 2 Inspector window?

Basically this. There may have been two inspector panels at some point, but this is my layout preset.

Hi,
I upgrade my project to 2022.3.9 and virtual camera can go outside border when play. This’s a bug?
9280615--1300180--upload_2023-9-8_13-52-55.png
P/S: I check again and find difference:
-2.8.9: when virtual camera change size , confiner will update
-2.9.7: confiner don’t update and need call Invalidate Cache manual

Try clicking invalidate cache if the camera is still off that may be a bug.

In Play Mode if virtual camera zoom will over confiner

Hello again,

We don’t recommend changing orthographic size when using the confiner. It’s something we experimented with in the past but the performance cost of updating the confiner would be too high.

The way around that would be to have one virtual camera per size you would need with their own confiner and switching vcam when you need a different orthographic size.

Let us know if that helps :slight_smile:

Hello… I know I’m late to the party, but… yup, I’m here for the same problem, but I’m using Unity 2021.3.21f1 LTS

NullReferenceException: Object reference not set to an instance of an object
Cinemachine.Editor.CinemachineSceneToolUtility+<>c.<.cctor>b__21_0 () (at Library/PackageCache/com.unity.cinemachine@2.9.7/Editor/Utility/CinemachineSceneTools.cs:272)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <57a8ad0d1492436d8cfee9ba8e6618f8>:0)

How do we fix this again…?

Start by upgrading to CM 2.10.0. Let us know if you still have the issue after that.

Hmm… I went to the Package Manager and typed in ‘Cinemachine’, and I’m updated to the latest version, Cinemachine 2.9.7, and there’s no updates that I can find that lead to 2.10.0. Should I downgrade it? If so,I’m guessing by deleting it and reinstalling it?

Again, I’m on Unity 2021.3.21f1 LTS (and unfortunately, due to the size of my project right now, upgrading to 2022 or higher is almost impossible at this point in time), if that makes a big difference (because it’s recommending version 2.8.9 to me)

You don’t need to upgrade all of Unity, just Cinemachine.
You can try with 2.9.7 if you like.
You can still install 2.10.0, despite the lies that the package manager tells you.
Here is how: How do I install a specific version of Cinemachine?

ahh, the good old deceiving software issues :stuck_out_tongue: - I Installed it, and will give it a test run whenever possible

On a serious note, can you recommend me an alternative solution to the ‘Mathf.Clamp’ function? I’m trying to develop a ranger’s aiming state for my own third person game, and everytime I place that function in, it messes with the ‘Tick()’ (Tick is the ‘Update()’ equivalent, but for my state machine. I’m sure you know that, just saying it if you didn’t), because whenever my player accesses the aiming function, it automatically places him on the edge of it.

I apologize if this is the wrong place for it, but can you please have a look at my state code and see if you can identify where the problem is? It’s been bothering me for 2 days now

using RPG.States.Player;
using UnityEngine;

public class PlayerRangerAimingState : PlayerBaseState
{
    // MOUSE MOVEMENT AND SENSITIVITY
    private float mouseX;
    private float mouseY;
    private float sensitivity = 100f;

    // CLAMP VALUES
    private float maxXRotation = 80f;
    private float minXRotation = -80f;

    private readonly int RangerStateBowLoadHash = Animator.StringToHash("RangerStateBowLoad");

    public PlayerRangerAimingState(PlayerStateMachine stateMachine) : base(stateMachine) {}

    public override void Enter()
    {
        stateMachine.Health.OnTakenHit += OnTakenHit; // Bug fix, when the player takes a hit

        Debug.Log($"Player has entered Ranger Aiming State");
        stateMachine.InputReader.RangerAimCancelEvent += CancelAim;
        stateMachine.rangerAimingCamera.m_Priority = 11;
        stateMachine.Animator.CrossFadeInFixedTime(RangerStateBowLoadHash, stateMachine.CrossFadeDuration);

        // Capture the initial camera rotation
        mouseX = stateMachine.transform.eulerAngles.y;
        mouseY = stateMachine.transform.eulerAngles.x;
    }

    public override void Tick(float deltaTime)
    {
        if (stateMachine.Fighter.GetCurrentWeaponConfig().HasProjectile() && !stateMachine.Fighter.CheckForProjectileAndSufficientAmmo())
        {
            // (DEBATABLE IDEA) needs ammo, but no ammo in the Quiver? Switch to freelook and block aiming
            stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
            return;
        }

        if (stateMachine.InputReader.IsAttacking && !stateMachine.CooldownTokenManager.HasCooldown("RangerFiringCooldown"))
        {
            // Cooldown is over, and player is attempting to attack? Go back to firing arrows:
            stateMachine.SwitchState(new PlayerRangerFiringState(stateMachine));
            return;
        }

        HandleRotation(deltaTime);
        Move(deltaTime);
    }

    public override void Exit()
    {
        stateMachine.Health.OnTakenHit -= OnTakenHit; // Bug fix, when the player takes a hit

        Debug.Log($"IsAttacking: {stateMachine.InputReader.IsAttacking}");
        Debug.Log($"Player has exited Ranger Aiming State");
        stateMachine.InputReader.RangerAimCancelEvent -= CancelAim;
        stateMachine.rangerAimingCamera.m_Priority = 9;

        if (stateMachine.InputReader.IsAttacking)
        {
            // No rotation modifications will be done here, that'll just ruin everything
            return;
        }
        else
        {
            // if you're not attacking, reset the y-axis euler rotation
            // (because you're going back to FreeLook State, from 'CancelAim')

            // Reset the y-axis rotation to zero:
            Quaternion resetYRotation = Quaternion.Euler(0, stateMachine.transform.eulerAngles.y, 0);
            stateMachine.transform.rotation = resetYRotation;
        }
    }

    private void HandleRotation(float deltaTime)
    {
        float mouseXDelta = Input.GetAxis("Mouse X") * sensitivity * deltaTime;
        float mouseYDelta = Input.GetAxis("Mouse Y") * sensitivity * deltaTime;

        mouseX += mouseXDelta;
        mouseY -= mouseYDelta;

        // mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation); // <-- this is the troublesome line

        Quaternion targetRotation = Quaternion.Euler(mouseY, mouseX, 0);
        stateMachine.transform.rotation = targetRotation;
    }

    private void CancelAim()
    {
        SetLocomotionState();
    }

    void OnTakenHit(GameObject instigator)
    {
        // Makes sure that when the player gets hit, he goes to the right state and not mess this up
        // (Bug Fix)
        if (stateMachine.InputReader.IsRangerAiming)
        {
            stateMachine.SwitchState(new PlayerRangerAimingState(stateMachine));
        }
        else stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
    }
}

I labelled it as ‘// ← this is the troublesome line’. That would be highly appreciated :smile:

(I tried posting this as a question in and of itself, but got no response earlier, so I figured I’d ask here)

So Mathf.Clamp() is a very simple function that isn’t going to mess with anything. Are you sure that the problem isn’t in your logic? This line looks suspect:
mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation); // <-- this is the troublesome line Why are you clamping mouseY instead of mouseX?

On a side note, if you want to paste code into a post, please use the little code button up on the toolbar, it make things much more readable :slight_smile:
9882372--1425723--upload_2024-6-10_8-22-55.png

Apologies for the coding mess, I’m still new to this forums page. Will use the button for installing code moving forward :slight_smile: (Edit: I fixed it above)

Well, because I want the Y-axis, i.e: the up and down axis in my project, to be clamped between two values, so that he doesn’t go into a full vertical rotation

Right now, that’s what he does without the limits, but placing the limits brings him, as soon as he returns from the Ranger Firing State, to be clamped to a single side, before the mouse movement gets back in action, which does not look natural at all

I’m trying my best with what I know. For now, this is what I managed to achieve :smile: