Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mixing between cameras in a dynamic list?

Discussion in 'Cinemachine' started by CitronMaane, Oct 11, 2019.

  1. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    Hi!
    I've been using the mixing camera in a project to spatially blend between virtual cameras in relation to player movement, which works very well. However, it has come to my attention that the mixing camera is static.

    Is there a way to mix a collection of cameras the same way the mixing camera does but with a dynamic list?

    Edit: What i mean by spatial blend:
     
    Last edited: Oct 11, 2019
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Mixing camera is not static. It will mix its vcam gameObject children, which is a dynamic list
     
    valentinlop likes this.
  3. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    Hey Thanks for the reply!

    hm, i guess the documentation for the mixing Camera has an error or am i missing something?
    https://docs.unity3d.com/Packages/com.unity.cinemachine@2.2/manual/CinemachineMixingCamera.html

    When I add the camera in my test script I wanted to set the weight and for some reason it wasn't setting:

    Code (CSharp):
    1.  public struct BlendCamera
    2.     {
    3.         public CinemachineVirtualCamera camera;
    4.         public Transform originalParent;
    5.         public float weight;
    6.     }
    7.  
    8.     CinemachineMixingCamera mixingCamera;
    9.  
    10.     public BlendCamera blendCameraToAdd;
    11.  
    12.     [ContextMenu("Add")]
    13.     public void AddCamera()
    14.     {
    15.         blendCameraToAdd.camera.transform.SetParent(transform);
    16.         mixingCamera.SetWeight(blendCameraToAdd.camera, blendCameraToAdd.weight);
    17.         blendCameraToAdd.camera.gameObject.SetActive(true);
    18.     }
    19.  
    20.     [ContextMenu("Remove")]
    21.     public void RemoveCamera()
    22.     {
    23.         blendCameraToAdd.camera.transform.SetParent(blendCameraToAdd.originalParent);
    24.         blendCameraToAdd.camera.gameObject.SetActive(false);
    25.     }
    Edit:
    This is the error message:
    NullReferenceException: Object reference not set to an instance of an object
    Cinemachine.CinemachineMixingCamera.SetWeight (Cinemachine.CinemachineVirtualCameraBase vcam, System.Single w) (at PurgeGame/Library/PackageCache/com.unity.cinemachine@2.3.4/Runtime/Behaviours/CinemachineMixingCamera.cs:117)
    CameraMixingManager.AddCamera () (at Assets/Scripts/Camera/CameraMixingManager.cs:16)
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    The documentation is not wrong. The list is dynamic, but only the first 8 children are considered. This last is to get around a limitation in Timeline which is unable to animate array elements.

    For the error message, you have found a bug! Thank you, we will fix it for the next release.

    As a workaround, try adding this line:
    var x = mixingCamera.ChildCameras;

    before calling SetWeight(). That will force a rebuild of the internal cache.
     
  5. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    Ah alright, I misunderstood the documentation!
    Awesome it worked! Thanks for the help!
    Cinemachine is a brilliant tool!
     
    Gregoryl likes this.