I know of the activation track in Unity to activate objects, but is there a deactivation track? For example I want to deactivate one camera and enable the second at certain points in the track and reversing that later on.
There isn’t a deactivation track built-in, but it isn’t complicated to create one if that’s the route you want to go. There may be one on the asset store or GitHub that I’m unaware of.
There are options on the track that let you leave the object in what ever state you want when the timeline stops, so 2 activation tracks can be used to accomplish what you are looking for, if you use multiple clips on a track so the gap represents the area of deactivation.
Basically I have a case where the player is going to inspect an object in the game (during gameplay) so I want to use Timeline to deactivate the main camera and then switch to the inspection camera, move the latter to a certain point to look at the inspection item. Thus there is no set time for when each camera will be active or not (player can inspect an item for 1 minute or 10 minutes).
I was able to achieve this without Timeline but I thought – given we have a few situations like this, I would use Timeline to streamline the process.
Ah, I understand. You are look for event-based sequencing, not time-based. Timeline isn’t well suited to that yet, that usually can be done with script or more visual-scripting-esque tools.
We recently switched to using Timelines for more and more of our gameplay effects, and once we got used to it writing small Tracks+Clips to do these little scripting tasks worked out very well.
Simply put, where it says Debug.Log(“Clip started!”) and Debug.Log(“Clip done!” is where you’d add the logic to disable a game object.
Now to make it work with GameObject references, the way I’ve been doing it (maybe there is a more elegant way) is to declare your external reference in your Clip PlayableBehaviour (think of this as the logic that consumes values on the clip and does something with them, except in your case you don’t care about interpolated values on the clip just rather the fact that the clip is currently within scope of the current frame):
public class DeactivateBehaviour : PlayableBehaviour
{
public GameObject Target;
Then you can use Target.SetActive(false) at the “Clip started” line and Target.SetActive(true) at the “Clip done!” line. Note, don’t confuse the Clip PlayableBehaviour with the Mixer PlayableBehaviour. In my link the Mixer has only one empty function, don’t put anything there.
All thats left is to expose the reference on your Clip class (I’ll give the more complete code here):
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[Serializable]
public class DeactivateClip : PlayableAsset, ITimelineClipAsset
{
public ExposedReference<GameObject> Target;
// Create the runtime version of the clip, by creating a copy of the template
public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
{
ScriptPlayable<DeactivateBehaviour> playable = ScriptPlayable<DeactivateBehaviour>.Create(graph);
DeactivateBehaviour playableBehaviour = playable.GetBehaviour();
playableBehaviour.Target = Target.Resolve(graph.GetResolver());
return playable;
}
// Use this to tell the Timeline Editor what features this clip supports
public ClipCaps clipCaps
{
get { return ClipCaps.None; }
}
}
And that should be it! Use the rest of the boilerplate code from the original link.
This looks like exactly what we are after. Some of it does go above my head only because I am fairly new to Timeline, I’ll dig deeper today into the tutorials that talk about creating custom Playables and will try your approach.
If you get stuck, just ask, but that linked thread should get you 90% of the way, with the missing 10% being the GameObject Target reference described here