Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug Errors updating to Cinemachine 2.9.5 on Unity 2021.3.22f1

Discussion in 'Cinemachine' started by ShervinM, Apr 17, 2023.

  1. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    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:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Cinemachine.Editor.CinemachineSceneToolUtility+<>c.<.cctor>b__21_0 () (at Library/PackageCache/com.unity.cinemachine@2.9.5/Editor/Utility/CinemachineSceneTools.cs:272)
    3. UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <964670f15c6b47f9b8f9340732720473>:0)
    4.  
    5. NullReferenceException: Object reference not set to an instance of an object
    6. Cinemachine.Editor.CinemachineSceneToolUtility+<>c.<.cctor>b__21_0 () (at Library/PackageCache/com.unity.cinemachine@2.9.5/Editor/Utility/CinemachineSceneTools.cs:272)
    7. UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <964670f15c6b47f9b8f9340732720473>:0)
    8.  
    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 :(

    Any help would be greatly appreciated!
     
  2. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    200
    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
     
    ShervinM likes this.
  3. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    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?
     
  4. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    108
    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:

    Screenshot 2023-04-21 164430.png

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

    Screenshot 2023-04-21 164730.png
     
    Last edited: Apr 21, 2023
    KRWatkins likes this.
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    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.
     
    ShervinM and baumxyz like this.
  6. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    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!
     
    antoinecharton and Gregoryl like this.
  7. Elliott-Mitchell

    Elliott-Mitchell

    Joined:
    Oct 8, 2015
    Posts:
    88
    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?
     
  8. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    200
    Can you describe your layout or take a screenshot? Do you have something like 2 Inspector window?
     
  9. Elliott-Mitchell

    Elliott-Mitchell

    Joined:
    Oct 8, 2015
    Posts:
    88
    Basically this. There may have been two inspector panels at some point, but this is my layout preset.
     

    Attached Files:

  10. nam-hd23

    nam-hd23

    Joined:
    Aug 3, 2013
    Posts:
    5
    Hi,
    I upgrade my project to 2022.3.9 and virtual camera can go outside border when play. This's a bug?
    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
     
    Last edited: Sep 8, 2023
  11. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    200
    Try clicking invalidate cache if the camera is still off that may be a bug.
     
  12. nam-hd23

    nam-hd23

    Joined:
    Aug 3, 2013
    Posts:
    5
    In Play Mode if virtual camera zoom will over confiner
     
  13. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    200
    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 :)
     
  14. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    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...?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    Start by upgrading to CM 2.10.0. Let us know if you still have the issue after that.
     
  16. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    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)
     
    Last edited: Jun 9, 2024
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    Last edited: Jun 10, 2024
  18. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    ahh, the good old deceiving software issues :p - 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


    Code (CSharp):
    1. using RPG.States.Player;
    2. using UnityEngine;
    3.  
    4. public class PlayerRangerAimingState : PlayerBaseState
    5. {
    6.     // MOUSE MOVEMENT AND SENSITIVITY
    7.     private float mouseX;
    8.     private float mouseY;
    9.     private float sensitivity = 100f;
    10.  
    11.     // CLAMP VALUES
    12.     private float maxXRotation = 80f;
    13.     private float minXRotation = -80f;
    14.  
    15.     private readonly int RangerStateBowLoadHash = Animator.StringToHash("RangerStateBowLoad");
    16.  
    17.     public PlayerRangerAimingState(PlayerStateMachine stateMachine) : base(stateMachine) {}
    18.  
    19.     public override void Enter()
    20.     {
    21.         stateMachine.Health.OnTakenHit += OnTakenHit; // Bug fix, when the player takes a hit
    22.  
    23.         Debug.Log($"Player has entered Ranger Aiming State");
    24.         stateMachine.InputReader.RangerAimCancelEvent += CancelAim;
    25.         stateMachine.rangerAimingCamera.m_Priority = 11;
    26.         stateMachine.Animator.CrossFadeInFixedTime(RangerStateBowLoadHash, stateMachine.CrossFadeDuration);
    27.  
    28.         // Capture the initial camera rotation
    29.         mouseX = stateMachine.transform.eulerAngles.y;
    30.         mouseY = stateMachine.transform.eulerAngles.x;
    31.     }
    32.  
    33.     public override void Tick(float deltaTime)
    34.     {
    35.         if (stateMachine.Fighter.GetCurrentWeaponConfig().HasProjectile() && !stateMachine.Fighter.CheckForProjectileAndSufficientAmmo())
    36.         {
    37.             // (DEBATABLE IDEA) needs ammo, but no ammo in the Quiver? Switch to freelook and block aiming
    38.             stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
    39.             return;
    40.         }
    41.  
    42.         if (stateMachine.InputReader.IsAttacking && !stateMachine.CooldownTokenManager.HasCooldown("RangerFiringCooldown"))
    43.         {
    44.             // Cooldown is over, and player is attempting to attack? Go back to firing arrows:
    45.             stateMachine.SwitchState(new PlayerRangerFiringState(stateMachine));
    46.             return;
    47.         }
    48.  
    49.         HandleRotation(deltaTime);
    50.         Move(deltaTime);
    51.     }
    52.  
    53.     public override void Exit()
    54.     {
    55.         stateMachine.Health.OnTakenHit -= OnTakenHit; // Bug fix, when the player takes a hit
    56.  
    57.         Debug.Log($"IsAttacking: {stateMachine.InputReader.IsAttacking}");
    58.         Debug.Log($"Player has exited Ranger Aiming State");
    59.         stateMachine.InputReader.RangerAimCancelEvent -= CancelAim;
    60.         stateMachine.rangerAimingCamera.m_Priority = 9;
    61.  
    62.         if (stateMachine.InputReader.IsAttacking)
    63.         {
    64.             // No rotation modifications will be done here, that'll just ruin everything
    65.             return;
    66.         }
    67.         else
    68.         {
    69.             // if you're not attacking, reset the y-axis euler rotation
    70.             // (because you're going back to FreeLook State, from 'CancelAim')
    71.  
    72.             // Reset the y-axis rotation to zero:
    73.             Quaternion resetYRotation = Quaternion.Euler(0, stateMachine.transform.eulerAngles.y, 0);
    74.             stateMachine.transform.rotation = resetYRotation;
    75.         }
    76.     }
    77.  
    78.     private void HandleRotation(float deltaTime)
    79.     {
    80.         float mouseXDelta = Input.GetAxis("Mouse X") * sensitivity * deltaTime;
    81.         float mouseYDelta = Input.GetAxis("Mouse Y") * sensitivity * deltaTime;
    82.  
    83.         mouseX += mouseXDelta;
    84.         mouseY -= mouseYDelta;
    85.  
    86.         // mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation); // <-- this is the troublesome line
    87.  
    88.         Quaternion targetRotation = Quaternion.Euler(mouseY, mouseX, 0);
    89.         stateMachine.transform.rotation = targetRotation;
    90.     }
    91.  
    92.     private void CancelAim()
    93.     {
    94.         SetLocomotionState();
    95.     }
    96.  
    97.     void OnTakenHit(GameObject instigator)
    98.     {
    99.         // Makes sure that when the player gets hit, he goes to the right state and not mess this up
    100.         // (Bug Fix)
    101.         if (stateMachine.InputReader.IsRangerAiming)
    102.         {
    103.             stateMachine.SwitchState(new PlayerRangerAimingState(stateMachine));
    104.         }
    105.         else stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
    106.     }
    107. }

    I labelled it as '// <-- this is the troublesome line'. That would be highly appreciated :D

    (I tried posting this as a question in and of itself, but got no response earlier, so I figured I'd ask here)
     
    Last edited: Jun 10, 2024
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    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:
    Code (CSharp):
    1. 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 :)
    upload_2024-6-10_8-22-55.png
     
  20. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    Apologies for the coding mess, I'm still new to this forums page. Will use the button for installing code moving forward :) (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 :D
     
    Last edited: Jun 10, 2024
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    ok, I got confused because you were clamping mouse Y to min/max X values, but I get it now.

    Have you tried adding some Debug.Log statements to the code, to print out mouseYDelta and mouseY before and after clamping? That might give you a clue.

    Also (probably unrelated) mouseDelta values by their very nature already have deltaTime baked in, so you probably shouldn't be multiplying by deltaTime again. Instead, adjust the sensitivity.
     
  22. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    I added a debugger before and after, and as it turns out, it takes an entire rotation from about -80, to +290, back to +80... So there's a full rotation going on, as you can see in the screenshot attached

    So, should I delete the multiplication with 'deltaTime' and keep the sensitivity? (Edit: I just tried that. It became superfast, I was forced to put it back in)

    Here's the 'HandleRotation' code that got me the results in the screenshot:

    Code (CSharp):
    1.     private void HandleRotation(float deltaTime)
    2.     {
    3.  
    4.         float mouseXDelta = Input.GetAxis("Mouse X") * sensitivity * deltaTime;
    5.         float mouseYDelta = Input.GetAxis("Mouse Y") * sensitivity * deltaTime;
    6.  
    7.         mouseX += mouseXDelta;
    8.         mouseY -= mouseYDelta;
    9.  
    10.         Debug.Log($"MouseY before clamping: {mouseY}");
    11.         mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation);
    12.         Debug.Log($"MouseY after clamping: {mouseY}");
    13.  
    14.         Quaternion targetRotation = Quaternion.Euler(mouseY, mouseX, 0);
    15.         stateMachine.transform.rotation = targetRotation;
    16.     }
     

    Attached Files:

  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    Clearly Mathf.Clamp is doing what it's supposed to do.
    I was also hoping that you'd log the value of mouseYDelta. Can you do that?

    You should remove the multiplication by deltaTime and instead just make the sensitivity much lower until you have a speed that you like. As you have it now, sensitivity will change based on the frame rate, and you don't want that.
     
  24. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    Sure, I attached a screenshot below for that

    Ahh, I figured the problem out using a 'forbidden trick' (ChatGPT...). Apparently I learned that Unity handles the Euler Angles internally in its own way, and it needed counteracting by manually wrapping the angles myself. I did the changes, and got it to work as expected

    Here's what it came up with, without the debugs:


    Code (CSharp):
    1.  
    2.     private void HandleRotation(float deltaTime)
    3.     {
    4.         float mouseXDelta = Input.GetAxis("Mouse X") * sensitivity * deltaTime;
    5.         float mouseYDelta = Input.GetAxis("Mouse Y") * sensitivity * deltaTime;
    6.  
    7.         mouseX += mouseXDelta;
    8.         mouseY -= mouseYDelta;
    9.  
    10.         mouseY = NormalizeAngle(mouseY);
    11.         mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation);
    12.  
    13.         Quaternion targetRotation = Quaternion.Euler(mouseY, mouseX, 0);
    14.         stateMachine.transform.rotation = targetRotation;
    15.     }
    16.  
    17.  
    18.     private float NormalizeAngle(float angle)
    19.     {
    20.         while (angle > 180) angle -= 360;
    21.         while (angle < -180) angle += 360;
    22.         return angle;
    23.     }
    Yes, I can prototype around and get that fixed, no problems
     

    Attached Files:

  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    Great, that sounds like the right solution.
     
  26. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    Thanks again Greg for guiding me with the debugs, which eventually lead us to the correct solution. I will work on the sensitivity problem for now. Have a great day ahead :)
     
  27. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    @Gregoryl remember when you asked me to let you know if I still see the exact same error after updating to Cinemachine 2.10.0? Yup, I did, and it comes in numerous quantities that sometimes it hides any serious NREs that I have in my project
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,905
    Sorry but I don't remember the details. If it's the same issue that was happening to the person who started this thread, we were not able to reproduce it.

    The good news is that they described how they fixed it here: https://forum.unity.com/threads/err...-5-on-unity-2021-3-22f1.1426266/#post-8966055

    Can you try following those steps and lets us know if it helps?
     
  29. Bahaa_Soliman_97

    Bahaa_Soliman_97

    Joined:
    May 24, 2016
    Posts:
    35
    Hello again. Sorry, I just saw this right now, because I was on my way to ask a brand new question (and yes, it was the exact same problem as what the OP went through)

    For the time being, I'll keep this link into consideration (it rarely shows up, and it's not a big problem for me at this moment in time), as I'm still working on a bug that I can't seem to figure out :sweat_smile: