Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

[SOLVED] best way to debug impulses?

Discussion in 'Cinemachine' started by jamespaterson, Jan 7, 2020.

  1. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    402
    Hi,

    Cinemachine is great. But I always have a lot of trouble getting impulses to work (although so far I have always succeeded in the end!). At the moment I am using a cinemachine timeline track with a number of cameras and I just cant seem to get the impulse to be received. Is there a way to debug impulse responses, for example to log to console which cameras receive an impulse?

    Many thanks in advance!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,751
    Look at the code for CinemachineImpulseListener. Make a custom script, based on that, that responds to impulses by emitting a log message instead of shaking the camera. The key Impulse API call is this, to get the impulse signal:
    CinemachineImpulseManager.Instance.GetImpulseAt()


    Unless you have a lot of different impulse channels, the problem usually has to do with a limited radius on the signal emitted, and the camera being outside that radius. I would look in that direction if you find that cameras aren't receiving signals.
     
  3. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    402
    Thanks for your help i will try this out ASAP.
     
  4. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    402
    Thanks again for your help. As usual the problem was with my configuration, not cinemachine. If anyone is interested, i attach the little cinemachine extension I knocked up to output debug to console.

    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. namespace Cinemachine
    5. {
    6.     /// <summary>
    7.     /// An extension for Cinemachine Virtual Camera which listens for CinemachineImpulse
    8.     /// signals on the specified channels, and outputs debug information to console when received
    9.     /// </summary>
    10.     [SaveDuringPlay]
    11.     [AddComponentMenu("")] // Hide in menu
    12. #if UNITY_2018_3_OR_NEWER
    13.     [ExecuteAlways]
    14. #else
    15.     [ExecuteInEditMode]
    16. #endif
    17.     public class CinemachineImpulseDebugListener : CinemachineExtension
    18.     {
    19.         /// <summary>
    20.         /// Impulse events on channels not included in the mask will be ignored.
    21.         /// </summary>
    22.         [Tooltip("Impulse events on channels not included in the mask will be ignored.")]
    23.         [CinemachineImpulseChannelProperty]
    24.         public int m_ChannelMask = 1;
    25.  
    26.         /// <summary>
    27.         /// Enable this to perform distance calculation in 2D (ignore Z).
    28.         /// </summary>
    29.         [Tooltip("Enable this to perform distance calculation in 2D (ignore Z)")]
    30.         public bool m_Use2DDistance = false;
    31.  
    32.         protected override void PostPipelineStageCallback(
    33.             CinemachineVirtualCameraBase vcam,
    34.             CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    35.         {
    36.             if (stage == CinemachineCore.Stage.Aim)
    37.             {
    38.                 Vector3 impulsePos = Vector3.zero;
    39.                 Quaternion impulseRot = Quaternion.identity;
    40.                 if (CinemachineImpulseManager.Instance.GetImpulseAt(
    41.                     state.FinalPosition, m_Use2DDistance, m_ChannelMask, out impulsePos, out impulseRot))
    42.                 {
    43.                     Debug.Log("CinemachineImpulseDebugListener on: "+gameObject.name+" got impulse"+Quaternion.Angle(impulseRot,Quaternion.identity).ToString("F5")+" "+impulsePos.magnitude.ToString("F5"));
    44.                 }
    45.             }
    46.         }
    47.     }
    48. }
    49.  
     
    Gregoryl likes this.