Search Unity

The State Driven Camera doesn't work with Animator Override Controllers

Discussion in 'Cinemachine' started by tnaseem, Apr 12, 2018.

  1. tnaseem

    tnaseem

    Joined:
    Oct 23, 2009
    Posts:
    149
    I've started moving over to Cinemachine for all my game camera needs, and have got most of it working rather nicely. Loving it so far!

    I'd like to utilise the State Driven Camera, to switch between virtual cameras depending on what the player is doing, but I've hit a snag...

    It appears that setting Animated Target to an Animator which references an Animator Override Controller (rather than an Animator Controller) doesn't bring up any animation layers and, subsequently, no animation states either.

    Of course, adding the actual base Animator Controller does work, but this seems like a bit of an oversight for not supporting override controllers too, unless I'm missing something obvious!

    Is there a way around this, or do I need to redo my Animator Override Controllers and replace with the base controller? I don't want to do this, as everything is so nicely laid out - I have a BaseHuman animator controller, with override controllers for specific types of humans (male, female and child).

    Any help or advice most appreciated!

    Unity 2017.4.1f1 // Cinemachine 2.1.10
     
    Last edited: Apr 12, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @tnaseem Indeed it is a small oversight in the Editor code for the State-Driven-Camera. Thanks for reporting it! Here's a patch, just drop it in your project, replacing the file of the same name.

    Let me know how that works out for you.
    Thanks!
     

    Attached Files:

    tnaseem likes this.
  3. tnaseem

    tnaseem

    Joined:
    Oct 23, 2009
    Posts:
    149
    Many thanks, Gregory. Works a treat!

    I presume this will make it into the next release? Just want to make sure in case it gets overridden in the next update. I can keep a copy of it hanging around then.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Glad to hear it. The fix will be in the next update. Thanks again.
     
    tnaseem likes this.
  5. Snigros

    Snigros

    Joined:
    Jun 12, 2018
    Posts:
    37
    Hi,

    I came across this thread in the process of trying to figure out how to get multiple state driven cameras (that are using multiple animator layers) to work. Initially I thought this might have been the solution to my issue - however from looking at the code above and my current version of CineMachine/Unity things seemed to have moved on since then. That said I am posting this query here as it appears to be related to the basic issue raised above.

    My current setup is using a free look camera as the primary camera, which switches to another free look camera when the player starts sprinting (triggered by a "sprint" state in the base layer of the animator).

    This all works fine - but I can't get it to work in combination with another virtual camera for an "over left shoulder view" when the "aim" state is triggered in the animator (which is on a different layer). I am using a separate camera for this as there does not appear to be a way to select multiple layers (and hence states) in the Layer drop-down on the State Driven Camera script.

    I am using CineMachine 2.2.8 with Unity Pro 2018.3.0f2.

    Any suggestions for the "best" way to configure multiple state driven cameras (triggered by states across multiple animator layers) would be much appreciated. Thanks.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The StateDrivenCamera can only look at one layer at a time, because it needs to take on only one state at a time, and looking at multiple layers can produce ambiguous results.

    One way to do what you want is to have 2 SDC's, one for Normal mode and one for Aim mode. Enable one or the other, depending on whether you are in Aim mode.
     
  7. Snigros

    Snigros

    Joined:
    Jun 12, 2018
    Posts:
    37
    Gregoryl - thanks for your reply.

    I had already figured out that I needed two SDCs (given you can't have one SDC work with states across multiple animator layers). The bit I am having difficulty understanding is how to trigger the Aim SDC when the Aim state is entered. I can get both of my SDCs to work if there is only one SDC in the scene - but not both. I had assumed it can be achieved by adjusting the various camera priorities, and using custom blends on the camera brain - but so far I just can't seem to get the right combination (it will not swap to the aim camera when the aim state is entered if my other SDC is active).

    I also tried activating the Aim camera in code when the Aim button is pressed - but so far haven't got this to work either. I expect I am missing a "basic" concept somewhere - but despite a lot of searching I have not yet found any examples of how to configure multiple SDCs (with multiple animation layers)...

    Ideally what I am after is some guidance for how to use the "over the shoulder vcam view" in combination with a centralised cross hair that is "moved" as per the usual free look camera control (e.g. with the right joystick) while simultaneously still supporting player/gun rotation (to align with the cross hair...aka the sort of behaviour that is provided when using Vinicius Marques excellent Cover + Shooting System - Third Person Shooter asset - but using CineMachine virtual cameras in place of the original camera scripts. Hope this makes sense...and thanks again for your assistance.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    In your code that gets called when Aim mode is entered, you just need to activate the Aim mode SDC's game object, and deactivate the other SDC. Do the reverse when you go out of Aim mode. The Brain's default blend will make the transition, unless you set up a custom blend between those vcams.

    Do you have other vcams in your scene, that are not children of the two SDCs you mentioned? If so and one of them has higher priority than the SDC you're activating, it might be taking control. Highest priority wins.

    Have a look at these threads, they are also talking about the over-the-shoulder aim concept.
    https://forum.unity.com/threads/ove...-sight-zoom-for-tps-game.620827/#post-4212421
    https://forum.unity.com/threads/bes...s-style-target-lock-using-cinemachine.606418/
    https://forum.unity.com/threads/freelook-to-freelook-how-to-aim-consistently.610105/#post-4106611
     
  9. Snigros

    Snigros

    Joined:
    Jun 12, 2018
    Posts:
    37
    Gregoryl - thanks again for your assistance. The links you have provided above will be very useful. Cheers, S.
     
  10. GVLS_STUDIO

    GVLS_STUDIO

    Joined:
    Oct 13, 2020
    Posts:
    1
    Hello! I had the same issue, my solution was to create an animated target different from the player, so when (in my case) the player was shooting the animator of that object would change state from "normal" to "shooting". That not only solved this problem but now I don't have to set which cam should go with every state of my player's animator. Hope I helped!:)