Search Unity

Bug Freelook camera prefab throws null ref errors, then corrupts scene camera

Discussion in 'Cinemachine' started by toomasio, Dec 21, 2020.

  1. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    Anytime I try to make a prefab of a freelook camera and try to adjust settings, I get a bunch of null ref errors, the Bottom, Middle, Top "Rigs" copy themselves to the scene, and it completley corrupts my scene camera until I delete it and start over.

    Unity 2020.2.0f1

    error:
    I am assuming it's trying to find follow and look at targets that are not there because it is a prefab, but it is annoying when I just want to create a prefab for easy of adjusting settings sake.

    Another feature that could be useful would be using your scriptable object pattern to just create "Free Look Settings" and we can save them as different files in the project, drag them into whatever camera if this bug cannot be resolved.

    Thanks,
     
  2. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    This only happens when not in play mode as well. As soon as I hit play it snaps to normal. It is trying to find the rigs in the script.

    other error:
     
  3. XochiInteractive

    XochiInteractive

    Joined:
    May 21, 2018
    Posts:
    19
    I'm also having this same issue in Unity 2019.3.6f1. Have you hade any progress on this?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Can you try upgrading to the latest CM 2.7.1? Does the problem still occur?
     
  5. XochiInteractive

    XochiInteractive

    Joined:
    May 21, 2018
    Posts:
    19
    I updated Cinemachine and deleted my camera in scene and added another to replace it. This resolved my issue and haven't had it since. Thanks!
     
    riteshkaashyap456 and Gregoryl like this.
  6. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    26
    I know there's a solution here, but I just want to confirm I also had this bug with 2.6.8 and by updating to 2.7.2 and deleting the camera and re-adding it it was ok. I had to redo all the settings which was a bit of a pain!

    It seemed to be related to the rigs somehow (top, middle, bottom) and they went missing.
     
  7. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    26
    Actually, strike that! I've just had the same thing happen again! Not quite the full error but the rigs have randomly appeared in the hierarchy again...




    It doesn't seem to have actually resulted in the same errors in the console this time though...

    @Gregoryl - any thoughts?
     
  8. Chregu

    Chregu

    Joined:
    Jan 7, 2018
    Posts:
    3
    I have the same issue (Unity 2019.4.22f1, Cinemachine 2.7.2)
    Freelook Prefab gets corrupted and the Top, Middle and Bottomrig become a seperate gameobject in the scene


    NullReferenceException: Object reference not set to an instance of an object
    Cinemachine.CinemachineFreeLook.InternalUpdateCameraState (UnityEngine.Vector3 worldUp, System.Single deltaTime) (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Behaviours/CinemachineFreeLook.cs:359)
    Cinemachine.CinemachineCore.UpdateVirtualCamera (Cinemachine.CinemachineVirtualCameraBase vcam, UnityEngine.Vector3 worldUp, System.Single deltaTime) (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Core/CinemachineCore.cs:355)
    Cinemachine.CinemachineVirtualCameraBase.UpdateCameraState (UnityEngine.Vector3 worldUp, System.Single deltaTime) (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Core/CinemachineVirtualCameraBase.cs:448)
    Cinemachine.CinemachineBlend.UpdateCameraState (UnityEngine.Vector3 worldUp, System.Single deltaTime) (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Core/CinemachineBlend.cs:124)
    Cinemachine.CinemachineBrain.ManualUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Behaviours/CinemachineBrain.cs:350)
    Cinemachine.CinemachineBrain.LateUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.2/Runtime/Behaviours/CinemachineBrain.cs:325)
     
  9. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    @myazuid, seeing the Top-, Middle-, and BottomRig after changing the prefab is "by design" by the prefab team for legacy reasons. The HideFlags are stripped away when prefabs are saved.
    However, this should not corrupt your data, and it should fix itself after some time or when you enter playmode.
     
  10. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I can't reproduce the error message in 2.7.2+, @Chregu.
    Could you provide more detail on how you got the error messages, or could you send me a project where I could reproduce the issue (DM me) or could you submit a bug report?
     
  11. castrojoaquin91

    castrojoaquin91

    Joined:
    Mar 22, 2016
    Posts:
    3
    Hey guys i had the same problem and fixed it doing this:

    It seems if you're using a prefab, for some reason, it loses the direction of the Transform its pointing at.
    So the only thing you have to do is enter to the prefab of your FreeLookCamera and fill the "Follow", "Look At", and also the TopRig, MiddleRig and BottomRig "Look At Override" with the prefab or the object you want it to point at.
    Doing this your FreeLookCamera will instanly recover the direction of your prefab and won't give you more errors in editor mode.

    Also, I don't know if it was caused by this, but I think the problem started when I changed to the 2D viewport to work with the UI.

    I hope this helps someone, sorry for my english, if I did not express myself well just ask me and I'll try to explain it better :)
     
    Last edited: Oct 26, 2021
  12. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    356
    That's all well and fine, unless your Follow and Look At are something in the Scene, NOT the Prefab. You CAN'T assign something not contained in the Prefab.

    You know, I've been a HUGE evangelist for Unity since 2006. I've gotten a ton of my AAA developers to embrace it and use it, as well as plenty of indies and hobbyists. I've wasted energy evangelizing and wasted even more of my own time with this engine over the past 15 years, but no more. I'm so sick and tired of things just deteriorating in my hands. It's absolutely RIDICULOUS. No more. I'm done.
     
  13. bezenyo

    bezenyo

    Joined:
    Mar 28, 2021
    Posts:
    2
    Hope this also helps anyone: I noticed this problem when I created a new prefab, call it "GO2", from an already existing game object prefab that had a CinemachineFreeLook component attached, called "GO1". The existing game object prefab, GO1, was set as my "Live Camera" in the CinemachineBrain component. Basically, the problem disappeared when I opened GO1 prefab and ensured the priority was higher than GO2. I apologize if this is confusing or does not work for you. Again, just trying to help.