Search Unity

CinemachineBrain.BlendTo(VCam) method or similar?

Discussion in 'Cinemachine' started by giantdoor, Nov 11, 2019.

  1. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    I am fully aware of the desired workflow and setup required by Cinemachine to work (changing priority of virtual cameras, or mix groups), but I was wondering if something like a BlendTo override method exists.
    Something that would allow me to provide a VirtualCamera to a Brain and have it blend to it in X seconds, regardless of the layer the VCam is on.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    In fact there is such an API in the Brain, and it is used by Timeline to control the current vcam and blends. However, is this something that you really need? Why can't you just give your new vcam a higher priority and activate it when you need it? Blend time can be controlled by adding an entry to the Custom Blends asset.
     
    Last edited: Nov 11, 2019
  3. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    Because we're doing a split-screen game, where each player has it's own set of virtual cameras on their player-specific layer, so they only influence that player's brain.

    However, there are situations where P1 and P2 will be using a single camera, in this case the active one of P1; to dynamically merge the views, I'd love to force P2's brain to transition to P1's currently active vCam, before turning it off.

    Basically what happens in this gif, but in reverse and at runtime, instead than timeline-driven.

    Thank you so much for the insanely quick answer btw <3

    And yes, I was wondering because I noticed that in the Timeline you can transition to vCams regardless of the layer they are on.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Why don't you make a third layer for common vcams, and make sure that both brains can see that layer too, in addition to their own vcam layers?

    Nice gif, btw!
     
  5. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    Because that would mean duplicating all player cameras in the game, as each player will have one vCam per orange character in his line of characters (see this gif to get what I mean, though in this case both player have only one orange guy) +1. Another thing I thought would be creating a vCam clone at runtime; I could clone P1 active camera, set it's layer to P2, transition to it and then trash everything, would that work?
    Thanks! We're trying to use Cinemachine as a in-game camera management tool as we have a very particular game which needs a lot of variables to be taken in consideration; but sometimes we feel like we're trying to push it too far ^^"
     
    Last edited: Nov 11, 2019
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I don't quite follow. P1 has vcamA, P2 has vcamB. P1 and P2 might have other vcams also, but currently not active. Now you want to make a vcamC that both brains can activate, that both brains can blend to simultaneously. Is that right? So just choose a spot for your new vcam, create it, give it a high priority, put it on the "common" layer, and activate it. Where is the extra duplication?

    That could work also, but it seems like extra work for nothing.

    I like the results. Do keep us posted with your progress and don't be shy about asking questions. We are happy to help. Pushing too far is a good thing, and we fully support your efforts!
     
  7. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    I don't need Both players to blend to it, I just need P2 to blend to P1 active vCam OR to a camera that is in the same position of the currently active P1 vCam. As P1 could have N+1 cameras, it means that each camera needs a copy that P2 can use to transition to.

    That's why making a runtime clone could save some time.
    Otherwise, the API extension you were talking about is the Brain.SetCameraOverride() method that I see in the CinemachineMixer.cs, right?

    Also, we're trying to make a setup that doesn't limit us to only 2 players, but that is virtually player-number-independent.

    We're trying to, one thing at a time. Eventually I will have tons of questions on the Cinemachine collider component, when used together with a target group as a frame composer :D
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    ok, I understand better, thanks.

    Here's an idea: when it's time for P2 to blend to P1's vcam, temporarily set the culling mask of P2's Camera to include the P1 vcam layer, and make sure that P2's vcam is on a lower priority than P1's. No duplication necessary, and it will work even if P1 is currently blending.

    And you can do the same thing in reverse when starting from a common vcam and splitting off.
     
    Last edited: Nov 11, 2019
  9. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    That sounds like a solution, as Players hold the vCam layermask in a public variable.
    Do you have suggestions on how to synchronize a Coroutine with a float blend parameter, with the current blend of a brain?
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    What do you mean by "the current blend"? What information are you looking to record?

    Is this question related to the previous questions in this thread? If so, then you don't need to do this. Changing the culling mask will do the whole job, as the brain will remember the outgoing vcams, even if they are on a layer that's not included in the culling mask.
     
  11. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    It's related as the visual effect shown in the gifs I previously linked is achieved together with a UI setup used to mask the camera viewport while it gets blended from fullscreen to half.
    This would need a reverse viewport blend while the camera viewports go back to cover the whole screen.
    As this time the cinemachine blend is not taking place in the timeline, I won't be using a custom clip to do the viewport blending as I'm doing in my cuscene (like in this gif, I swear that's the last one I post here) and therefore I would create a Coroutine to run the viewport blend. As a Cinemachine Blend doesn't necessarily have a fixed timespan (or am I wrong? What happens if vCam A or B of the blend are moving?) I'd rather synch my Coroutine to the brain blendamount.
    If the question is too unrelated, I can create a new thread ^^"
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The blend time is controlled by the brain. Whether the vcam you're blending to/from is moving or not is irrelevant. The blend will just go to whatever the incoming vcam is doing.

    One way to manage this would be: when you begin the transition by changing the culling mask, at the same time you can set the default blend time of the brain to be the desired duration of the transition. The blend will take that long, regardless of what the vcams are doing. Start your other process at that time also. At the end of that time, clean up by restoring the brain's default blend time.
     
  13. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    aaa.gif
    boom.

    Now I only need to revert it when players detach. Thank you so much for the help, I will post another gif when I'm done <3

    Also I've seen @Adam_Myhill appreciates the outcome too :D
     
    Gregoryl likes this.
  14. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    AA.gif
    Done :D
    I need to optimize the code a bit, but i think the effect is pretty neat.

    @Gregoryl I'm now trying to force jump the P2 camera to the P1 position right before splitting the view, but I onlly managed to do so in a coroutine, becauseif I only turn on that vCam (as I'm doing for the merge part) i need to wait a frame after i turn on P2 brain for the cut to happen. Is that by design?

    Because in this thread you seem to hint otherwise.