Hello,

Is there a way to activate a timeline /cinemachine event?

Maybe activate/call a script using nodes that play a timeline during a event?


Thanks


  • I'm using Cinemachine extensively in my game.

    Right now I have triggers on points of interest that activate a timeline associated with that POI when it is "discovered" for the first time.

    See the Timeline Controller script attached to the CrystalBaseTimeline Gameobject? That plays any Playable Director/Timeline attached to the parent object (in this case Crystal BaseTimeline)

    image

    Note it is NOT set to play on Awake, which is how it gets triggered.

    Here's the code for triggering it. This was given by a Unity staff guy on the Cinemachine forum I believe.
    //using System.Collections;
    //using System.Collections.Generic;
    //using UnityEngine;
    //using UnityEngine.Playables;

    //public class TimelineController : MonoBehaviour
    //{

    // public TimelineController playableDirector;

    // public void play()
    // {

    // playabledirector.play();

    // }


    //}

    using UnityEngine;
    using UnityEngine.Playables;

    public class TimelineController : MonoBehaviour
    {
    public PlayableDirector timeline;

    // Use this for initialization
    void Start()
    {
    timeline = GetComponent<PlayableDirector>();
    }


    void OnTriggerExit(Collider c)
    {
    if (c.gameObject.tag == "Player")
    {
    timeline.Stop();
    }
    }

    void OnTriggerEnter(Collider c)
    {
    if (c.gameObject.tag == "Player")
    {
    timeline.Play();
    }
    }
    }

    Here is my timeline for the object. Note that for it to work I have a separate Camera with the Cinemachine brain attached (not my main camera with the player controller.) My timeline activates this camera, called CutCam, when it's triggered. My Cinemachine virtual cams and their blends then render to it instead of my original main camera.

    I did notice that I had to move the activation for CutCam a couple of frames ahead in the timeline or it activated automatically and cancelled out my main camera. Not sure if that's a bug or I'm doing it wrong.

    For the camera to switch back after the timeline is done, I have the activation track for the CutCam set to Post Playback State: Revert.

    image




    There's also some more advanced activation and player start/stop scripts in the Cinemachine sample scene shown at Unite Austin here:

    https://drive.google.com/file/d/0B1ToZGrZLWKcZi1BWVlqM1dBN00/view




  • Ok Awesome thanks! I will look at this.


  • You can call functions via ORK events using a Call Function node.

    E.g. for starting a timeline (using a PlayableDirector component):
    - component name: PlayableDirector
    - function name: Play

    The target object naturally needs the component attached and set up with the timeline you want to play :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.