Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

CM v2.1 Release Candidate

Discussion in 'Cinemachine' started by Adam_Myhill, Sep 24, 2017.

  1. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @JacobSmaga Thanks for your vigilance in noticing this, and for your effort in packaging and sending your project.

    In fact the bug was a resource leak in CinemachinePostProcessing, in the special case where you have a PostProcessing layer on the camera, but no PostProcessing extensions on the vcams. I've attached a patch. Just drop it in your project and the problem will go away. The patch will be part of the next CM release.

    Thanks again for your help. The Cinemachine team salutes you!
     

    Attached Files:

    JakubSmaga likes this.
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    I'm glad that I could help. :)
     
  3. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    Hello,
    Was wondering if there is a way to change or get access of the variables within "Body" and "Aim" of a virtual camera.
    I would really like to change things like height offset and heading bias property in runtime with code, but except for a codepiece I found earlier here, about extensions to change cameras aim offset, I couldn't find how to access all the other variables :O
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @Farelle Have a look at the Scripting scene, in the Cinemachine examples. That should point you in the right direction. If you still have questions after that, don't hesitate to post here.
     
  5. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    RC8 when? :rolleyes:
     
  6. Pacosmico

    Pacosmico

    Joined:
    Jan 16, 2014
    Posts:
    11
    Hola!

    First, I want to thank you for all the hard work you are doing with this project, it's awesome, I picked it up yesterday and I was able to do exactly what I wanted in less than an hour. That is amazing. You saved me so much time and headaches... I even feel kind of cheating : P

    I wanted to ask for a feature, although I understand you might have other priorities, and It's not something really vital:

    I have been getting used to the UnityEvents, and I noticed several (most?) of Cinemachine Components have few things exposed in a way that can be linked to UnityEvents. For example, I would love to use a UnityEvent to change the Weight of a VCam on the Mixing Camera Component. Or, Change the weight of an element of Target Group. But while trying that I noticed very few Functions and Properties where exposed to be linked through the UnityEvents.
    I mean, the Cinemachine doesn't need that, but it would be cool if it had it.

    Again, thank you very much, Amazing work

    Hasta luego!
     
  7. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    425
    RC7, Just noticed on Win10 Unity 2017.1.1p1 that the vcams are not showing the game window guides and the brain isn't showing any debug text. Not sure why yet... anyone else having problems with the guides?

    There's lots of VR and Oculus audio stuff happening in the scene (but disabled as we're setting up Cinemachine-based video capturing) that might be interfering with things. If I find anything useful I'll add it to this post.
     
  8. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    141
    RC7 on 2017.2.0f3

    Missing a few :
    using UnityEngine.PostProcessing; in MinDrawer and GetSetDrawer.

    There is a difference between editor and play mode when using Target Groups and Rotation on GroupAverage, it works as expected in Manual mod.

    In edit mod, light is behind the sphere
    upload_2017-11-3_11-34-17.png

    In play mod, camera is different.
    upload_2017-11-3_11-34-57.png

    Also blending curves for rotation between two cameras are different in this version compared to 2.0.1 resulting in unwanted very quick rotations. Tried to tweek this through blending curves but the result is very touchy. Shouldn't we be able to have different blending curves for position and rotation ?

    Besides that, CM is a must have.
     
    Last edited: Nov 3, 2017
  9. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    What is the recommended way of piping input from custom input handlers into Cinemachine rigs (free look, orbital)? We're using Rewired and are not using standard Unity input axes directly, so I'm wondering how to send input to Cinemachine through code to accommodate that.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @bac9-flcl There's a delegate in CinemachineCore that Cinemachine uses to get input. You can override that.

    Code (CSharp):
    1. class CinemachineCore
    2. {
    3. [...]
    4.         /// <summary>Delegate for overriding Unity's default input system.  Returns the value
    5.         /// of the named axis.</summary>
    6.         public delegate float AxisInputDelegate(string axisName);
    7.  
    8.         /// <summary>Delegate for overriding Unity's default input system.
    9.         /// If you set this, then your delegate will be called instead of
    10.         /// System.Input.GetAxis(axisName) whenever in-game user input is needed.</summary>
    11.         public static AxisInputDelegate GetInputAxis = UnityEngine.Input.GetAxis;
    12. [...]
    13. }
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Great idea for the UnityEvents. We'll look into that.
    In the meantime you could probably just add a custom component of your own that exposes events, e.g. SetPriority, and it can pass that to the vcam.
     
    Pacosmico likes this.
  12. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Thanks! You've thought of everything, it seems. :)
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @bac9-flcl We thought of as many things as we could think of thinking of. Always open to new ideas :)
     
  14. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    I suppose one possible change is providing an option to pipe axis inputs using a method with an integer ID argument rather than a string name (to avoid unnecessary string use), but that seems simple enough to implement on our side and probably unwarranted in the main version if most people will be using standard Unity input system. :)
     
  15. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    @Gregoryl
    By the way, could you recommend a possible solution for making FoV transitions less jarring? One easily reproducible case is to set the top and mid FoV of free look component to close low values and setting the bottom rig to a high value (e.g. 35-50 on top/mid rigs and 70-80 for bottom rig). This setup results in an abrupt subjective jump of the camera distance from the target, because edges of the screen drastically change their content depending on the field of view. I wonder if there is a good formula I can apply to dynamically alter the tracking distance for virtual cameras, inverting the subjective "zoom out" effect of higher fields of view.

    To rephrase, is there a good formula that grabs FoV value as an argument and outputs a nonlinear multiplier for tracking distance, which can be used to keep edges of the screen sitting as approximately same points in the scene?
     
    Last edited: Nov 3, 2017
  16. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Last edited: Nov 3, 2017
  17. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    @JacobSmaga - great point. The Timeline UX is having a lot of work put towards it. Many new features in 2017.2 and more coming after that. We know it's currently a little fiddly.. Check 2017.2 and you'll see even more in 2017.3 (and of course even more after that as well)

    I'll get an answer on your specific issue and when that will land. Cheers.
     
    JakubSmaga likes this.
  18. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    I wonder what might be causing LateUpdate in CinemachineBrain to balloon enormously in terms of execution time if you leave your game running. Here is a screenshot of a profiler after half an hour of a scene with just one Free Look rig targeting an unmoving object and the Brain set to LateUpdate mode. Everything starts off smooth, but over time, LateUpdate in CinemachineBrain climbs up to 30ms per frame and more.



    I'm using the latest RC version of 2.1.

    Destroying the Free Look rig in the middle of that play session completely removes all the slowdown, and undoing that operation makes 30ms per-frame delays return, as you can see on this graph:



    I think the issue might originate in ProcessActiveCamera method called from LateUpdate in CinemachineBrain, because commenting out that call seemed to eliminate the slowdown - cost of LateUpdate stayed locked at around 0.17-0.18. Nothing jumps out to me in that method aside from new objects being declared in a few places (but that shouldn't cause a gradual slowdown, just some cyclical GC to mop up unused temporary objects), but maybe this will give you some ideas.
     
    Last edited: Nov 4, 2017
  19. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Download the patch that @Gregoryl made (Top of the page) and check if it fixes your problem. (I've also had this problem and this patch fixed this)
     
    Gregoryl likes this.
  20. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Thanks a lot, totally missed that post! :)
     
    JakubSmaga likes this.
  21. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Got a feature request for the collider component - right now it does nothing to prevent entry into colliders from the front, which makes it very easy to sink the camera into part of the scenery through zooming or orbiting. Casting back towards the camera from the look position is great, but another mode preventing the camera from following the look target into a collider would be very helpful too.

    I took a stab at modifying the collider component directly (thanks for the source access, folks!) and I wonder if I'm on the right track with the following modification of returned position (lines 47-54).

    Code (csharp):
    1.  
    2. private Vector3 PreserveLineOfSight(ref CameraState state, ref VcamExtraState extra)
    3. {
    4.     Vector3 displacement = Vector3.zero;
    5.     if (state.HasLookAt)
    6.     {
    7.         Vector3 cameraPos = state.CorrectedPosition;
    8.         Vector3 lookAtPos = state.ReferenceLookAt;
    9.         Vector3 pos = cameraPos;
    10.         Vector3 dir = pos - lookAtPos;
    11.         float targetDistance = dir.magnitude;
    12.         float minDistanceFromTarget = Mathf.Max(m_MinimumDistanceFromTarget, Epsilon);
    13.         if (targetDistance > minDistanceFromTarget)
    14.         {
    15.             dir.Normalize();
    16.             float rayLength = targetDistance - minDistanceFromTarget;
    17.             if (m_DistanceLimit > Epsilon)
    18.                 rayLength = Mathf.Min(m_DistanceLimit, rayLength);
    19.  
    20.             if (m_AvoidObstacles)
    21.             {
    22.                 // Make a ray that looks towards the camera, to get the most distant obstruction
    23.                 Ray ray = new Ray (pos - rayLength * dir, dir);
    24.                 rayLength += PrecisionSlush;
    25.                 if (rayLength > Epsilon)
    26.                 {
    27.                     RaycastHit hitInfo;
    28.                     if (Physics.Raycast (
    29.                         ray, out hitInfo, rayLength, m_CollideAgainst.value,
    30.                         QueryTriggerInteraction.Ignore))
    31.                     {
    32.                         // Pull camera forward in front of obstacle
    33.                         float adjustment = Mathf.Max (0, hitInfo.distance - PrecisionSlush);
    34.                         pos = ray.GetPoint (adjustment);
    35.                         extra.AddPointToDebugPath (pos);
    36.                         if (m_Strategy != ResolutionStrategy.PullCameraForward)
    37.                         {
    38.                             pos = PushCameraBack (
    39.                                 pos, dir, hitInfo, lookAtPos,
    40.                                 new Plane (state.ReferenceUp, cameraPos),
    41.                                 targetDistance, m_MaximumEffort, ref extra);
    42.                         }
    43.                     }
    44.                 }
    45.             }
    46.  
    47.             else if (m_AvoidFrontObstacles)
    48.             {
    49.                 Ray rayForward = new Ray (pos, -dir); // ray originating at camera and going forward from it
    50.                 RaycastHit raycastHitForward;
    51.                 if (Physics.Raycast (rayForward, out raycastHitForward, m_MinimumDistanceInFront, m_CollideAgainst.value))
    52.                 {
    53.                     pos -= (raycastHitForward.point - pos); // subtract this vector from position to get away from collider in front of us
    54.                 }
    55.             }
    56.         }
    57.         if (m_CameraRadius > Epsilon)
    58.             pos += RespectCameraRadius(pos, state.ReferenceLookAt);
    59.         else if (mCameraColliderGameObject != null)
    60.             CleanupCameraCollider();
    61.         displacement = pos - cameraPos;
    62.     }
    63.     return displacement;
    64. }
    The hits seem to be reported correctly when I debug them, but "pos" variable modification seems to have no effect (I can still enter a stack of box colliders head on); so I might be surfacing the position away from offending front collision incorrectly. The position handling is a bit labyrinthine there, so maybe I'm missing something.
     
    Last edited: Nov 5, 2017
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    I think you're trying to add a feature that's already there. If you want the camera to be pulled in front of the obstacle that's closest to the target, then set the strategy to "pull camera forward".

    upload_2017-11-6_9-45-11.png

    For the code, modifying pos should do the trick. Maybe you have the "Avoid Obstacles" checkbox checked by mistake in the inspector.
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Did the patch fix it?
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Within the FreeLook there isn't really a way out of the box to link the FOV to the positioning algorithm. What you might try to do is to make a custom extension that sets the FOV according to the camera distance from the target. That way, you won't need to modify FreeLook. You can use the CinemachineFollowZoom extension as an example (make a copy, rename it, and modify the code. Due to its inheritance, your new extension will appear in the vcam's Extensions menu).

    The math in the FollowZoom code is there for calculating FOV to get an object to appear a certain size on the screen, but I'm not sure you can get exactly what you're looking for. "Background" is a bit vague. How much of the screen space it will occupy will depend on its size and distance from the camera. You will need to take that into account.
     
  25. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Yup, smooth sailing so far! :)

    Sorry for not providing enough context - I'm already using that mode and it was not the feature I attempted to describe. Let's start from the beginning. I'm setting up a camera rig for a turn-based strategy game where look target sits on a plane and moves horizontally from some basic inputs. Here is a gif of me testing the rig in an abstract test environment that might help. You can see the look target as a small green light in it (ignore the blue light, that's mouse-driven pointer):
    The collisions in the game are not provided by a continous hull mesh collider - instead, since levels are voxel-driven and destructible, we use a pool of box colliders. Pull-forward strategy works great in that environment for as long as look target remains in open space, but we can't really restrict player movement around the map, so it's very easy to encounter the following situation - especially when buildings are move that one block thick:



    The third case depicted above can be avoided - I came up with a relatively simple solution based on several "feeler" rays, which allows me to detect when look target is situated in a place where pull-forward strategy would give very undesirable result - and shut the collision handling down:



    This solves the issue with pull-forward strategy, but there remains another way of entering buildings (which we want to avoid, since we don't have geometry in there and it's not a pretty view) - while look target sits inside a building (same or another, doesn't matter), you can orbit or zoom into any collider in your path:



    To solve this, we need another collision handling strategy: pull backward. Instead of attempting to find a position where look target is unoccluded (by casting from look target towards virtual camera origin), we can cast from the origin point towards the look target, and push the camera out.

    This is what I was attempting to implement - a new strategy that prevents the camera from entering colliders head on instead of attempting to find a point from which look target can be seen. Switching to such a strategy when feeler rays from image 2 return some hits would make our camera rig quite resistant to entering buildings.

    P.S.: To think of it, maybe some sort of a trigger collider can accomplish that better than a raycast - to prevent other kinds of movement (like sideways orbiting and backward target shifting) from allowing you to enter anything. So, it would be a "pull away from any collisions", not "pull backward" strategy :)



    I already do zoom by dynamically altering free look rig orbits (that's how zoom in the gif on top of the post works - you can easily get desired distance to the subject by setting orbit height and radius derived distance and angle with some trigonometry), so what I'm looking for is a formula for calculating distance multiplier based on FoV, which I'll be able to apply to my zooming logic to compensate for screen size diiference induced by different FoV on top/mid/bottom rigs. Thanks for FollowZoom mention, I'll take a look screen pixel size calculation there! :)
     
    Last edited: Nov 6, 2017
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    I see. In fact the CM collider system assumes that the target is never inside a collider, i.e. that the collision rules are the same for it and for the vcams. When it goes inside, all bets are off.

    So yes, if you detect that the target is inside a collider, you can switch algorithms as you describe. If I were implementing it, I would avoid modifying the current collider, and instead create a new kind of collider extension, which I would enable whenever the target is inside a collider, while disabling the standard CM collider.
     
  27. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Makes sense to disable the current collider component while enabling a new one, keeps CM classes untouched and easily updateable. What would you recommend to access? Virtual camera classes are a bit labyrinthine with their handling of positions, so I'm not sure where to start without wrecking some smoothing/prediction/testing behaviour virtual cameras have to do. Is there some safe public method for overriding virtual camera positions or moving them?

    Btw, that situation can easily arise even without moving into a collider - narrow tunnels can be a case where pull-forward would be equally undesirable. Is there a way to configure the collider component to abort pull-forward attempts if resulting camera position is closer to look target than a certain threshold? E.g. if we're tracking a 2m sized object, we would probably want the camera rig to completely ignore pull-forward outcomes bringing the camera closer than 2-4 meters since the object won't even fit on the screen in that case.
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Yes. Use the CinemachineExtension API. That's what Collider does. It modifies the "positionCorrection" channel in the camera state, which will not interfere with vcam damping. CinemachineConfiner is a slightly simpler example that does a similar thing. I suggest you make a copy of an existing extension, like collider or confiner, and use that as a starting point to discover the API.
     
  29. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Awesome, glad to see such a nice API! :)
     
  30. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    That's what the MinimumDistanceFromTarget field is for
     
  31. Razouille

    Razouille

    Joined:
    Jan 25, 2013
    Posts:
    39
    Really good job with your plugin, can't work without it now in all my cutscenes ! But I got an issue : I added a possibility to skip a cutscene, so I force the time of the current timeline to be the duration, then use the Evaluate function to force an update before stopping it. But when I do that, the virtual camera is not updated and stay at the initial position, while all the other clips were well updated. Do you know how I could fix that ?
    Btw, I need to to disable the Brain component on the camera if I want it to stay at the last position after the cutscene ends, because if I don't, it resets or use the last virtual camera, don't know if it's the right way to do that ?

    EDIT : if I force a call of "UpdateVirtualCameras + ProcessActiveCamera" just before the brain deactivation, it works fine (adding this on OnDisable function doesn't work).
     
    Last edited: Nov 7, 2017
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Not a good idea to disable the brain and hack with those methods - no guarantees that it will continue to work. There must be a better way.

    The way the CinemachineTracks work in timeline is by overriding the current vcam. When the timeline clip ends (whether because of the clip ending in timeline, or the timeline itself ending), the override is removed, and whatever vcam would normally be active takes control.

    When you set the timeline to the end, probably the update function is seeing that it's time to remove the override, that's why the timeline vcam doesn't update: it gets disabled. What happens if, when skipping the cutscene, you set the time to just before the end?

    If you want the timeline's vcam to remain active after the timeline stops, you must have a piece of code that makes it the active vcam at the end of the timeline (or during, it doesn't matter). Set its priority higher than the other vcams, and it will remain active after timeline ends. When it's time to transition back to another vcam, you can lower its priority again.
     
    Last edited: Nov 7, 2017
  33. Razouille

    Razouille

    Joined:
    Jan 25, 2013
    Posts:
    39
    As I must be able to skip several timelines at the same time (during the same frame), I can't set the time just before the end. I'm building a QTE system, so I need 1 different timeline for each branching.
    I tried the solution of setting a higher priority to the last camera when the timeline ends and it works well, thanks for the tip !
     
  34. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    @Gregoryl
    I referenced CinemachineConfiner to implement a simple push-back collision handler component, but certain frames seem to ignore it, seemingly allowing the object to move forward without asking for displacement from the component.

    * https://i.imgur.com/y1yTD9r.gifv

    The component is using Physics.ComputePenetration (precise method for finding penetration between colliders, added in Unity 5.6) to find exact displacement needed to push the collider out - it's normally used on player controllers and such. The class is pretty short, similar to Confiner, so I wonder if you could take a look and guess where the jittery, inconsistent application of displacement is coming from?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using Cinemachine.Utility;
    5. using System;
    6.  
    7. namespace Cinemachine
    8. {
    9.     [DocumentationSorting (22, DocumentationSortingAttribute.Level.UserRef)]
    10.     [ExecuteInEditMode]
    11.     [AddComponentMenu ("")] // Hide in menu
    12.     [SaveDuringPlay]
    13.     public class CinemachineColliderSphere : CinemachineExtension
    14.     {
    15.  
    16.         /// <summary>The collider used for intersections with environment</summary>
    17.         [Tooltip ("The collider used for finding intersections with environment")]
    18.         public SphereCollider m_SphereCollider;
    19.  
    20.         /// <summary>How gradually to return the camera to the bounding volume if it goes beyond the borders</summary>
    21.         [Tooltip ("How gradually to return the camera to the bounding volume if it goes beyond the borders.  Higher numbers are more gradual.")]
    22.         [Range (0, 10)]
    23.         public float m_Damping = 0;
    24.  
    25.         /// <summary>
    26.         /// When enabled, will attempt to resolve situations where the line of sight to the
    27.         /// target is blocked by an obstacle
    28.         /// </summary>
    29.         [Space]
    30.         [Tooltip ("When enabled, will attempt to resolve situations where the line of sight to the target is blocked by an obstacle")]
    31.         public bool m_AvoidObstacles = true;
    32.  
    33.         /// <summary>Which layers are checked for penetration</summary>
    34.         [Tooltip ("Which layers are checked for penetration")]
    35.         public LayerMask m_LayerMask;
    36.  
    37.         private int colliderCount = 0;
    38.         private Collider[] collidersCollected = new Collider[10];
    39.         private Collider colliderExamined = null;
    40.         private Vector3 penetrationDistance;
    41.         private float penetrationDepth;
    42.         private Vector3 displacement;
    43.  
    44.  
    45.  
    46.  
    47.         public bool CameraWasDisplaced (CinemachineVirtualCameraBase vcam)
    48.         {
    49.             return GetExtraState<VcamExtraState> (vcam).confinerDisplacement > 0;
    50.         }
    51.  
    52.         private void OnValidate ()
    53.         {
    54.             m_Damping = Mathf.Max (0, m_Damping);
    55.         }
    56.  
    57.         class VcamExtraState
    58.         {
    59.             public Vector3 m_previousDisplacement;
    60.             public float confinerDisplacement;
    61.         };
    62.  
    63.         public bool IsValid
    64.         {
    65.             get
    66.             {
    67.                 return m_SphereCollider != null;
    68.             }
    69.         }
    70.  
    71.         protected override void PostPipelineStageCallback
    72.         (
    73.             CinemachineVirtualCameraBase vcam,
    74.             CinemachineCore.Stage stage, ref CameraState state, float deltaTime
    75.         )
    76.         {
    77.             if (m_AvoidObstacles && IsValid && stage == CinemachineCore.Stage.Body)
    78.             {
    79.                 displacement = Vector3.zero;
    80.                 colliderCount = Physics.OverlapSphereNonAlloc (m_SphereCollider.transform.position, m_SphereCollider.radius, collidersCollected, m_LayerMask);
    81.                 if (colliderCount > 0)
    82.                 {
    83.                     for (int i = 0; i < colliderCount; ++i)
    84.                     {
    85.                         colliderExamined = collidersCollected[i];
    86.                         if
    87.                         (
    88.                             Physics.ComputePenetration
    89.                             (
    90.                                 m_SphereCollider,
    91.                                 m_SphereCollider.transform.position,
    92.                                 Quaternion.identity,
    93.                                 colliderExamined,
    94.                                 colliderExamined.transform.position,
    95.                                 colliderExamined.transform.rotation,
    96.                                 out penetrationDistance,
    97.                                 out penetrationDepth
    98.                             )
    99.                         )
    100.                         {
    101.                             displacement += penetrationDistance * penetrationDepth;
    102.                         }
    103.                     }
    104.                 }
    105.  
    106.                 VcamExtraState extra = GetExtraState<VcamExtraState> (vcam);
    107.                 if (m_Damping > 0 && deltaTime >= 0)
    108.                 {
    109.                     Vector3 delta = displacement - extra.m_previousDisplacement;
    110.                     delta = Damper.Damp (delta, m_Damping, deltaTime);
    111.                     displacement = extra.m_previousDisplacement + delta;
    112.                 }
    113.  
    114.                 extra.m_previousDisplacement = displacement;
    115.                 state.PositionCorrection += displacement;
    116.                 extra.confinerDisplacement = displacement.magnitude;
    117.             }
    118.         }
    119.     }
    120. }
    121.  
    I wonder why CinemachineConfiner and CinemachineCollider displace the camera in a relatively stable manner while this component jitters constantly, seemingly skipping displacement every second frame.
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @bac9-flcl Try using state.CorrectedPosition instead of m_SphereCollider.transform.position
     
  36. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    795
    Thanks, that helps, frame-to-frame position is very stable now :)
     
  37. Hellwaiker

    Hellwaiker

    Joined:
    Jan 8, 2016
    Posts:
    87
    I love the 2d features! aaaaaand this probably have been mentioned a lot. But Unity blog post about 1017.2 says this is out on asset store and it's confusing.
     
  38. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    @Hellwaiker - yes that's confusing...we know. It's going up on the Asset Store so...very...soon.......
     
    Corvwyn and KB73 like this.
  39. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    I've noticed that CM has really big performance impact at the start. (0-60 frames = ~50 to ~0.70 ms)
    Is there any way to fix/improve that?



    Also why does I have GUI.Repaint in my profiler (which creates GC) even though i have debug UI disabled?
     
    Last edited: Nov 11, 2017
  40. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @JacobSmaga Look at the number of calls. CinemachineBRain.AfterPhysics() is being called 16 times per frame. That means you're getting 16 physics frames for one normal frame for the first frame in your game, hence the slow frame rate. That number settles right down in the next couple of frames, and all is well after that. I think that many systems in Unity (including CM) distribute some initial setup and caching over the first few frames, in order to be efficient in the frames that follow.

    I tried it with the project you sent me. First frame looks like this: upload_2017-11-13_10-3-52.png

    You can see that 208 virtual cameras are being updated per frame. This number is cut in half every frame, so that 4 frames later we have this:

    upload_2017-11-13_10-5-58.png
     
    JakubSmaga likes this.
  41. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,200
    I'm also getting some huge slow down with cinemachine at the moment, but mine seems to be a bit different than the other posts in this thread. Something to do with FX



    I have a default global post processing stack on my camera, but my active cinemachine camera isn't even using the new cinemachine postprocessing so I have no idea why it needs to do anything. I do have a cinemachine post processing script on another, inactive camera.

    Also 7k+ getcomponents calls in a frame...?

    This is RC6, I'm going to update to RC7 in hopes that it fixes it.
     
  42. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Have you tried @Gregoryl's patch? https://forum.unity.com/threads/cm-v2-1-release-candidate.497202/page-3#post-3274302
     
    Gregoryl likes this.
  43. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,200
    No I haven't. Missed that somehow, thanks l'll give that a shot.
     
  44. LBrocklehurst

    LBrocklehurst

    Joined:
    Nov 16, 2012
    Posts:
    3
    I'm getting some strange behaviour when switching the Confiner during runtime - is this something I should be doing?:

    Code (CSharp):
    1. //Set Camera's bounds to new zone's
    2.         CinemachineBrain brain = Camera.main.transform.GetComponent<CinemachineBrain>();
    3.         ICinemachineCamera activeCam = brain.ActiveVirtualCamera;
    4.         CinemachineConfiner confiner = activeCam.VirtualCameraGameObject.transform.GetComponent<CinemachineConfiner>();
    5.         Collider2D newBounds = Zones[currentZone].GetComponent<CompositeCollider2D>();
    6.         confiner.m_BoundingShape2D = newBounds;
     
  45. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Did the patch fixed your issue?
     
  46. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Suggestion: Icons

    What's happening: Right now both CM Brain and any vCam use the same icon in the scene view, which makes it really hard to know where the current camera is without selecting it in the hierarchy.

    GIF: https://gyazo.com/c376b45d9e6d9df1d82030983897edeb (You can see that I'm switching between 3 different cameras (In the timeline window) but you can't really tell which vCam is being used in the scene view, there's kind of shadow but from far distance it's really hard to see it)

    What should happen: Developer should know which vCam is currently active without selecting camera in the hierarchy window - or selecting vCam in the timeline window.

    How to fix it: Use different icon for CM brain/vCam.

    Even if it would be just a simple icon color change like: CM brain - black, vCam - Red; it would help a lot.​

    Thanks, have a great day.

    Jacob

    Update:
    What about an option to change icon colors in the Edit->Preferences?​
     
    Last edited: Nov 16, 2017
    Adam_Myhill and Gregoryl like this.
  47. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    Add this call after changing the shape:
    Code (CSharp):
    1. confiner.InvalidatePathCache();
     
  48. LBrocklehurst

    LBrocklehurst

    Joined:
    Nov 16, 2012
    Posts:
    3
    Fantastic, that worked - thanks.
     
    Adam_Myhill likes this.
  49. Hellwaiker

    Hellwaiker

    Joined:
    Jan 8, 2016
    Posts:
    87
    How can I get access to camera transform position from another script, while camera brain is controlling the camera?
    Position is always returned as if camera was not moving, even when Cinemachine is moving it and in inspector Main camera shows that it's moved.
     
  50. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,703
    @Hellwaiker If you're asking about reading the position of the Unity camera, then you can access it as usual - this is what the inspector does. The brain really moves the camera, and its transform's position will reflect that.
     
unityunity