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

Feedback InvalidCastException: Unable to cast object of type 'PlayableDirector' to type 'CinemachineBrain'.

Discussion in 'Cinemachine' started by Peter77, Nov 15, 2021.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,591
    Unity 2019.4.20f1, Cinemachine 2.6.10, Android Player

    In Cloud Diagnostics I see that very very few users run in the exception in our game:
    Code (CSharp):
    1. InvalidCastException: Unable to cast object of type 'PlayableDirector' to type 'CinemachineBrain'.
    2. CinemachineMixer.ProcessFrame (UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info, System.Object playerData) (at <00000000000000000000000000000000>:0)
    I couldn't find anything in our gamecode that would call this method or pass a PlayableDirector to something else.

    The CinemachineMixer.ProcessFrame implementation looks like this:
    Code (CSharp):
    1. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    2. {
    3.     base.ProcessFrame(playable, info, playerData);
    4.  
    5.     // Get the brain that this track controls.
    6.     // Older versions of timeline sent the gameObject by mistake.
    7.     GameObject go = playerData as GameObject;
    8.     if (go == null)
    9.         mBrain = (CinemachineBrain)playerData;
    10.     else
    11.         mBrain = go.GetComponent<CinemachineBrain>();
    12.     if (mBrain == null)
    13.         return;
    Any chance you would turn:
    mBrain = (CinemachineBrain)playerData;

    into
    mBrain = playerData as CinemachineBrain;

    instead? So that the code just early-outs, rather than throwing an exception.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks for the suggestion. It's already fixed on the CM trunk.
     
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,591
    Thank you for the reply. Do you happen to know in what version this fix landed or will land?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Should be in 2.8.3
    EDIT: Sorry, my mistake, it hasn't been backported. It's only in the 2.9.x family.
    There should be a pre-release of this before year end.
     
    Last edited: Nov 29, 2021
    Peter77 likes this.