Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MissingReferenceException from CameraBrain

Discussion in 'Cinemachine' started by Kev00, Jun 25, 2018.

  1. Kev00

    Kev00

    Joined:
    Dec 6, 2016
    Posts:
    229
    I don't think I'm destroying any CinemachineVirtualCamera's in my code so I'm not sure why I'm getting this error. I wasn't getting this error before upgrading.

    Thanks


    Code (CSharp):
    1.  
    2.  
    3. MissingReferenceException: The object of type 'CinemachineVirtualCamera' has been destroyed but you are still trying to access it.
    4. Your script should either check if it is null or you should not destroy the object.
    5. Cinemachine.CinemachineVirtualCameraBase.UpdateSlaveStatus () (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:375)
    6. Cinemachine.CinemachineVirtualCameraBase.get_ParentCamera () (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:207)
    7. Cinemachine.CinemachineBrain.IsLive (ICinemachineCamera vcam) (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:595)
    8. Cinemachine.CinemachineCore.IsLive (ICinemachineCamera vcam) (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:405)
    9. Cinemachine.CinemachineCore.UpdateAllActiveVirtualCameras (Int32 layerMask, Vector3 worldUp, Single deltaTime) (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:179)
    10. Cinemachine.CinemachineBrain.UpdateVirtualCameras (UpdateFilter updateFilter, Single deltaTime) (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:293)
    11. Cinemachine.CinemachineBrain.LateUpdate () (at C:/Users/x/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:242)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    It's possible that a camera got deleted somehow. I'll need to know a little more about the repro steps.

    Nonetheless, that bit of CM code could be made a little more robust by having it check for deleted objects. We'll get a fix in for the next release. Thanks for lettings us know.
     
  3. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    This could also happen when exiting play mode after upgrade to 2.2. Not 100%, but is still quit annoying.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Well, we did tighten up some code that might be behind this, but can't be sure without being able to consistently repro. If you find consistent repro steps please let us know.
     
  5. Kev00

    Kev00

    Joined:
    Dec 6, 2016
    Posts:
    229
    Yes, this is happening when I exit play mode. Due to the size of my project, I still haven't tracked down the offender.

    I'm creating vcams embedded in prefabs at runtime so perhaps it's not liking it when they get destroyed by the editor.
     
  6. Kev00

    Kev00

    Joined:
    Dec 6, 2016
    Posts:
    229
    I can reproduce this by deleting the currently active vcam from the scene.

    I can also access CinemachineCore.Instance.VirtualCameraCount without issue before and after this error occurs.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I'm able to delete the currently active vcam in the new version without issue. Also to exit play after vcams were instanced from prefabs. Looking good :)
     
  8. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    Code (CSharp):
    1. MissingReferenceException: The object of type 'CinemachineVirtualCamera' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. Cinemachine.CinemachineVirtualCameraBase.UpdateSlaveStatus () (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:375)
    4. Cinemachine.CinemachineVirtualCameraBase.get_ParentCamera () (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:207)
    5. Cinemachine.CinemachineBrain.IsLive (Cinemachine.ICinemachineCamera vcam) (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:595)
    6. Cinemachine.CinemachineCore.IsLive (Cinemachine.ICinemachineCamera vcam) (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:405)
    7. Cinemachine.CinemachineCore.UpdateAllActiveVirtualCameras (System.Int32 layerMask, UnityEngine.Vector3 worldUp, System.Single deltaTime) (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:179)
    8. Cinemachine.CinemachineBrain.UpdateVirtualCameras (Cinemachine.CinemachineCore+UpdateFilter updateFilter, System.Single deltaTime) (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:293)
    9. Cinemachine.CinemachineBrain.Start () (at C:/Users/Zhouyangxi/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:162)
    When exit playmode, this first error is caused by [CinemachineBrain.Start()], then error logs continue to popup by [LateUpdate()]. (BTW, Unity calls editor Start() before scenes are not completely reset?)

    I can't reproduce this bug in an empty project though...I'll try to figure out what's causing it, it's definitely related to prefab main camera and runtime instantiated vCam.
     
  9. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    this also happens to me constantly when exiting play mode in the editor after updating to 2.2:

    Code (CSharp):
    1. MissingReferenceException: The object of type 'CinemachineVirtualCamera' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. Cinemachine.CinemachineVirtualCameraBase.UpdateSlaveStatus () (at Packages/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:375)
    4. Cinemachine.CinemachineVirtualCameraBase.get_ParentCamera () (at Packages/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineVirtualCameraBase.cs:207)
    5. Cinemachine.CinemachineBrain.IsLive (Cinemachine.ICinemachineCamera vcam) (at Packages/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:595)
    6. Cinemachine.CinemachineCore.IsLive (Cinemachine.ICinemachineCamera vcam) (at Packages/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:405)
    7. Cinemachine.CinemachineCore.UpdateAllActiveVirtualCameras (System.Int32 layerMask, UnityEngine.Vector3 worldUp, System.Single deltaTime) (at Packages/com.unity.cinemachine@2.2.0/Runtime/Core/CinemachineCore.cs:179)
    8. Cinemachine.CinemachineBrain.UpdateVirtualCameras (Cinemachine.CinemachineCore+UpdateFilter updateFilter, System.Single deltaTime) (at Packages/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:293)
    9. Cinemachine.CinemachineBrain.Start () (at Packages/com.unity.cinemachine@2.2.0/Runtime/Behaviours/CinemachineBrain.cs:162)
    10.  
     
  10. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    195
    Any news about a release date of the fixed version? getting this error, too and not sure how to help myself without it :'D
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The fixed version (2.2.6) is available now in preview in the Staging repository. It's just getting a final QA pass before publication, but it's looking good.
     
    Toadilein, Thermos and mons00n like this.
  12. robrab2000-aa

    robrab2000-aa

    Joined:
    Feb 8, 2019
    Posts:
    117
    Hi, I seem to be having this issue after upgrading from 2018.2 to 2019.1 with cinemachine 2.3.4.

    Its fine in play mode but when I exit play mode i'm getting this message come up: error.PNG

    It looks like the live camera becomes unassigned on exiting play mode.

    This is the brain in 2018:

    2018.PNG

    This is the brain in 2019:
    2019.PNG

    This is the vcam its referring to in 2018:
    2018-vcam.PNG

    This is the vCam it should be referring to in 2019:
    2019-vcam.PNG

    Just wondering if there is a fix for this?

    Thanks
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Hmmm... we can't repro this. Can you set up a small demo project the shows this and send it to me?
     
  14. robrab2000-aa

    robrab2000-aa

    Joined:
    Feb 8, 2019
    Posts:
    117
    Hey, thanks for responding Gregoryl. I haven't been able to reporduce this in a fresh project however I have found that first of all, the issue only happens upon exiting play mode, and secondly, the issue stops as soon as I compile/sync. I.E. if I go into my ide, do anything (hit the space bar, save, and return to unity).
     
  15. robrab2000-aa

    robrab2000-aa

    Joined:
    Feb 8, 2019
    Posts:
    117
    So I seem to have finally gotten rid of the null reference.. by assigning the Solo to null?!?
    Code (CSharp):
    1. private void OnApplicationQuit()
    2. {
    3.     CinemachineBrain.SoloCamera = null;
    4. }
    Weird..
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Are you setting CinemachineBrain.SoloCamera anywhere else in your code?
     
  17. robrab2000-aa

    robrab2000-aa

    Joined:
    Feb 8, 2019
    Posts:
    117
    Yes, quite a few places I think. Switching it as needed. Interestingly we were having an issue where our main blend (we have a sort of time line with CamA and CamB positions on it. there is a blend when the playhead moves between them and then is solo'd to A if the playhead is < A and solo'd to B when the playhead is > B) was skipping to 100% B when at about 60% of the way through (This was not happening in the editor, just in WebGL and Standalone builds). Now that I've sorted out the null reference issue, this problem has magically dissapeared?? Very nice, but no idea why..
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Well, Solo wasn't designed to be used in-game, it's really there for authoring purposes only. If you're using it in new ways, that's fine, but it doesn't surprise me that you're getting some weirdness when you have dangling references in there.