Search Unity

Cinemachine vs Final IK - script execution order nightmare

Discussion in 'Cinemachine' started by mariusgeorge, May 17, 2019.

  1. mariusgeorge

    mariusgeorge

    Joined:
    Jan 29, 2016
    Posts:
    15
    Hi everyone,

    When a Cinemachine vcam is targeting something in a character's skeletal hierarchy, and that hierarchy is affected by IK, the vcam will target the wrong location, causing a terrible 1-frame latency and jitter situation.

    Final IK forces a certain order via its scripts, as shown below. So I attempted to drop CinemachineBrain below that. However - CinemachineBrain ALWAYS resets itself to 100, no matter what.

    This effectively means that it is impossible to get things into the correct order.

    Did anyone come across a solution or work-around for this?

    Please see here:

    script-order.png

    I will also reference this thread, which seems to imply it IS possible to move CinemachineBrain execution order: https://forum.unity.com/threads/tak...machinebrain-updates-camera-positions.547049/

    Any ideas?

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,246
    The problem is that CM is now a read-only package, and the script execution order is baked into the CMBrain's meta-file. Because the file is read-only, you can't modify it without doing a little extra work.

    Here are 2 possible workarounds:
    1. Make CinemachineBrain.cs.meta writable in your package cache (every Unity seat using the project will need to do this), or
    2. Embed the Cinemachine package into your project (copy it to your packages directory), then you can mod it and put it in source control.
     
    mariusgeorge likes this.
  3. mariusgeorge

    mariusgeorge

    Joined:
    Jan 29, 2016
    Posts:
    15
    Thanks for the suggested work-arounds. I wonder if there can be a more permanent solution in the near future, like being able to modify the execution order via some asset or property exposed on the CinemachineBrain?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,246
    Actually this is a more general problem that Unity needs to solve re. packages
     
    mariusgeorge likes this.
  5. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    123
    Almost 2020 and this problem makes the use of cinemachine for a serious project impossible.

    The square orange gizmo is the "Follow" transform, while the orange circle is the "LookAt" transform.
    So at this point, is there a permanent solution to that? and please don't tell me to use a "work around", i'd rather not use cinemachine at all.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,246
    That the script execution order is baked into the package is not a Cinemachine-specific problem, but a more general Unity scripting and packages limitation.

    Currently, it is possible to customize the script execution order of package scripts. You do it by embedding the package source into your project, and modifying the script execution order of the embedded script. It's like any other customization of package functionality.
     
  7. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    362
    What's the recommended way to do this on a mac?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,246
    I think you're better off embedding the whole package in your project and modifying it there. It's less error-prone.
     
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,095
    I think it would be a good idea to have Cinemachine update via API calls, a manual update if you will, just like Physics, Animator, Navmesh Agent or anything else. With Unity's Physics, you can update whenever you want.

    This means API can be as simple as Cinemachine.CinemachineBrain.autoUpdate = false;
    Followed by a brain update call in the developer's own code, in the order the developer wants.

    Then anyone with conflicts like this easily manage it, just like other parts of Unity - animators, physics, agents etc. It's a proven and known working thing already in Unity.
     
    Gregoryl likes this.
  10. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    362
    Cool. Would that impact on my ability to download future CM updates through the package manager if I move the package to the Asset folder? And if not, would my change get overwritten with every update?

    In other words, should I just the drag the folder over or should i do a git clone in my Assets folder and do the updating myself?
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,246
    Sadly, you will have to actively manage this.

    A git clone into your assets will import a lot of stuff that you don't actually need, but on the other hand might make updating a little easier.

    If you just copy the package over, then you will have to set the script order again every time you upgrade, unless you take care not to overwrite your local CinemachineBrain.cs.meta file which is where the order info is stored. With current versions of package manager, the copy needs to be done manually (future versions will more explicitly support package embedding - which is what you're doing).
     
    transat likes this.
unityunity