Search Unity

Impulse Event - Hold Forever vs Overlapping Events

Discussion in 'Cinemachine' started by flashframe, May 6, 2021.

  1. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Hi!

    I'd like to apply an impulse that is triggered and cancelled by player input. GetButtonDown starts the event, and GetButtonUp stops it. The player could press and release the button at any time, as many times as they like.

    Reading through the forum and documentation, there seems to be a couple of ways to achieve this.

    1. Create a short impulse event that is continuously fired as long as the button is held down, as per this solution by @Gregoryl
    https://forum.unity.com/threads/cre...e-that-can-turned-on-off.891304/#post-5872768

    2. Set the impulse definition to "Hold Forever", hold a reference to the Event when it is created and cancel it when the button is released. (Edit. If I hold a reference to an ImpulseEvent, and cancel it, can I recycle it by calling AddImpulseEvent() on the CinemachineImpulseManager?)

    Is either method preferred - or more in keeping with the way Cinemachine Impulses are expected to be used?

    If Hold Forever is used, does Sustain Time matter?

    Thank you!
     
    Last edited: May 6, 2021
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    I think solution 1 is the safer bet.
     
    flashframe likes this.
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Thank you!