Search Unity

Configure blend duration from code (zero editor)

Discussion in 'Cinemachine' started by frosted, Sep 17, 2021.

  1. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Is it possible to do this without modifying the scriptable object?

    The only way I've found to write this from code is:
    Code (csharp):
    1.  
    2.  
    3. var from = CinemachineBlenderSettings.kBlendFromAnyCameraLabel;
    4. var to   = **RUNTIME CREATED CAMERA**;
    5.  
    6. CinemachineBlendDefinition blend = CameraCoordinator.Get.Brain.m_CustomBlends
    7.   .GetBlendForVirtualCameras(from, to, CameraCoordinator.Get.Brain.m_DefaultBlend);
    8.  
    9. blend.m_Time  = **CALCULATED VALUE**;
    10.  
    11. CinemachineBlenderSettings customBlends = CameraCoordinator.Get.Brain.m_CustomBlends;
    12. customBlends.m_CustomBlends = new[]
    13. {
    14.   new CinemachineBlenderSettings.CustomBlend()
    15.   {
    16.     m_Blend = blend,
    17.     m_From  = from,
    18.     m_To    = to
    19.   }
    20. };
    21.  
    This modifies the scriptable object though, which stays after playmode (so the state between enter/exit play mode isn't the same - which is not good).

    I guess I could instantiate the referenced scriptableobjet, modify the clone and not write directly to the asset -- but is this really the best way to do this? All of this strikes me as ...ugh.

    Is there a better way?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    frosted likes this.
  3. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Thanks, that'll work. Might recommend renaming the parameter from defaultblend to currentBlend since you guys do a lookup to populate first (its not actually the default blend assigned in the brain).

    Also, as a side - why do so many properties have the m_ prefix? I'm guessing these were private members that you guys later decided to make public or something, but why not remove the prefix? Or do you use m_ to denote something else?
     
    Gregoryl likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The m_ thing is a historical aberration that we're now unfortunately stuck with :(
     
    frosted likes this.
  5. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Sorry, unrelated to thread title.

    I recently ported over input to the new input system.

    I have an orbital transporter.

    InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
    Cinemachine.AxisState.Update
    Cinemachine.CinemachineOrbitalTransposer.UpdateHeading

    I imported the cinemamachine package before the input system package - maybe this is cause?

    Is there some way to either resolve this or just disable the input? Is there a difference between orbital and regular outside of the input handling?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    You should see this in the vcam inspector. Press it.

    upload_2021-9-17_15-16-49.png

    Otherwise, you can just delete the axis name field in the Orbital Transposer. That will stop it from tying to read the old input system.

    upload_2021-9-17_15-17-46.png
     
    frosted likes this.
  7. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    No add input provider button.

    I'll just disable the axis. Unity_Iu9spMIgPR.png

    Thanks again!
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Maybe you have an older version of CM