Search Unity

Multiple Cinemachine Brains causes horrible-ness

Discussion in 'Cinemachine' started by mradfo21, May 10, 2018.

  1. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    So I need some guidance in the proper way to use multiple brains. With one brain in the scene Cinemachine functions perfectly. With more than one it freaks out and spins the cameras wildly. I want some cameras to be cuts, some to be blends, but using the blend list relies on the assumption that cameras already existed in the scene and I set up all the blends before hand.

    I dynamically create my cutscens / cameras (ala Mass Effect)

    My main interest is in using the Cinemachine Track in timeline, which seems to naturally want to have a static reference to the brain. But that reference I don't necessarily know where its going to be at run-time. I really wish Cinemachine and timeline could work together globally alter the blend type. I just don't have the kind of game where everything is static and in one big scene.

    Is there no way to use multiple brains on the same layer?
     
  2. Deleted User

    Deleted User

    Guest

    Hello,

    I think this is what you'll need. It will allow you to bind the brain component of a camera to a cinemachine track. You can use any Camera GO, not just Camera.main.

    Code (CSharp):
    1.  
    2.     PlayableDirector director = gameObject.AddComponent<PlayableDirector>();
    3.     TimelineAsset timeline = ScriptableObject.CreateInstance<TimelineAsset>();
    4.     director.playableAsset = timeline;
    5.     cinemachineTrack = timeline.CreateTrack<CinemachineTrack>(null, "Cinemachine track");
    6.     director.SetGenericBinding(cinemachineTrack, Camera.main.GetComponent<CinemachineBrain>());
    7.  
    8.  
     
  3. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    ah So i should write a component that looks for all cinemachine tracks under the heirarchy and fills in the brain with the current global brain?

    I think the Cinemachine Track is probably overkill for this. I bet im better off just writing custom timeline tracks to alter the global brain's blend modes

    would LOVE if a simple track like that existed!
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I don't understand why you need multiple brains. The paradigm is this:
    • 1 Unity Camera, with a brain on it.
    • Multiple vcams, on separate game objects. The active vcam drives the Unity camera at all times.
    • When you have an active CM Timeline track for the brain, its clips override the current active vcam. Blends are controlled by overlapping the clips in the timeline asset.
    • the previous post described how to dynamically bind scene objects to timeline assets
    If that doesn't help, maybe you can describe a little more fully what you're trying to achieve, and where it's going wrong.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Not a great idea to alter the brain's global blend mode IMO. Better to set up a Custom Blends asset on it, and configure it for the different blends you need. Vcam lookup is name-based for the blends, so just having a good naming system for them will accomplish the dynamic bindings.
     
  6. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    interesting.. didn't even realize it was string based! Does it do anything kind of filtering? Can I say.. "anything with CUT in the name" ?
     
  7. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    so it doesn't seem to be string based. It creates a magic enum out of scene assets. my cameras are all contained under a prefab. So how does it work under the hood? Can i just enter the string somewhere?

    upload_2018-5-10_15-26-29.png
     
  8. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    so heres the issue.. it works only if the cameras are in the scene

    so i built this! omg amazing!
    upload_2018-5-10_15-28-53.png

    then the moment i run the game and those elements aren't in the scene anymore it changes to this

    upload_2018-5-10_15-29-23.png


    sadly this makes the blend lists useless unless you have cameras ALWAYS in the scene. so you cant do any kind of dynamic stuff with it
     
  9. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    will code some custom solution i guess
     
  10. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    ok a good custom solution for this is to make N blend settings for whatever kind of blends you want and then at runtime SET the global brain to these settings

    upload_2018-5-10_16-13-25.png

    sry its a pic, but basically this works well for "make a cutscene then blend back to gameplay"