Search Unity

How to change Aim and Body via script

Discussion in 'Cinemachine' started by AquaGhost, Jun 9, 2019.

  1. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    Im not talking about the basic aim and follow values.
    I want to actually change Aim behavior in the dropdown. If I go into debug mode, it's a member variable that's part of the cm pipeline, and I can't figure out if I can edit this on the fly.
    Attached is an image of the thing I want to change.
    cmAim.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's possible, but under the hood what happens if that a behaviour is removed an another one added. The API is like this: vcam.AddCinemachineComponent<CinemachineComposer>() to put a Composer in the aim, for instance.

    However, it is not the recommended approach. Instead of making such a drastic change to a vcam, you'll get better results if you have a second vcam with the different settings and just enable it, allowing the brain to make a nice blend.
     
    avataris-io likes this.
  3. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    @Gregoryl Ok that seems to work well. This is an adjustment we are making on Start, so we arent using it to transition. It's basically a mode switch between two different ways of viewing.
    The one thing left to make it work right is to change a dolly offset. Im trying to GetCinemachineComponent<CinemachineTrackedDolly> to get the current one with all its settings, and then use that to reconstruct and add one with the edited offset. Is that the wrong way to do that? Seems like I cant edit the offset. Should i rethink that approach and maybe just edit the track itself on the fly?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @AquaGhost That approach should work. Why can't you edit the offset?
     
  5. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    Ok yeah it does. I was overthinking it like I might have to edit and re-add, but it allows me to edit it right away with the Get method.
     
    Gregoryl likes this.
  6. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Is this (the fact that 'adding' a component removes different named components if they happen to be 'related') documented anywhere? This is the top hit on Google for "cinemachine switch aim via script".

    (For what it's worth: I too am trying to workaround limitations with TrackedDolly. The lack of any aim system for it means I'm trying to find the least destructive way of making it Aim, and I figured I could switch the 'Aim' mode dependent on where along the path the camera is.

    But since the path position is part of the vcam, saying 'switch to another vcam' seems pretty bad too: now I have to write code to copy/paste all the properties of one vcam to the other, just so that they can switch. That's error prone code that is hard to maintain.

    Maybe the least bad workaround for TrackedDolly is to create N x virtual cameras, all of them on the dollycart, all of them (except one) disabled, and switch them on/off as it moves around?
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
  8. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    FWIW: putting N duplicated cameras on the same DollyCart, moving all at once at same speed, and invoking
    "vcam.MoveToTopOfPrioritySubqueue()" on one at a time when the dolly gets close to that specific camera's point-of-interest ... seems to work fine.
     
    Gregoryl likes this.
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Maybe that's the easiest way forward, if you don't mind managing all those vcams.
     
  10. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    For future reference (since it's not in the docs) -- is there no way to explicitly remove a stage? And so ... for stages like 'DoNothing' (which don't have a class?) there's no way for a script to re-instate the stage after the stage has been removed?

    (although I get your point that in general CM wants us to duplicate vcams instead of edit them, so usually we'd want to dupe-and-change, then delete the new one once its no longer needed (causing the old one to resume ... rather than directly edit the old one)
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes these things can be done by script. You have this API:

    CinemachineVirtualCamera.AddCinemachineComponent(),
    CinemachineVirtualCamera.GetCinemachineComponent(), and
    CinemachineVirtualCamera.DestroyCinemachineComponent().

    "Do Nothing" for any stage simply means not having a component on that stage.

    I should take this opportunity to mention that with CM 3.0 (currently in pre-release) the architecture is much less opaque, and the stages are implemented by ordinary Unity behaviours that you can add and remove in the normal way.
     
  12. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Yeah, CM3 sounds great. But it won't be available until 2025 - we can't use non-LTS versions of Unity, and for assetstore we can't require anything (we can 'use' it but only as an optional-extra - we cannot rely on it!) that's been LTS for less than 2 years. Every time a Unity team chooses to not backport fixes the public statements are all about 'you could upgrade to latest alpha of Unity', but they ignore reality: we don't have a choice, anything shared within a larger org, or published to assetstore, is by definition multiple years behind 'the latest unity' release.
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes, I hear you. Sometimes though, it's just not possible to backport without breaking too many eggs. CM3 is one of these cases. It's the cost of progress. We are are aware that some people will not be in a position to upgrade, so we will be fully supporting CM2 for some years.