Last active
April 21, 2025 13:05
-
-
Save leeprobert/83a32eb56d98cfd5610f92035486048e to your computer and use it in GitHub Desktop.
A Unity Timeline Signal extension to create Signals with a String parameter. You can add a Timeline track for this Signal Receiver.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System; | |
using UnityEngine; | |
using UnityEngine.Events; | |
using UnityEngine.Playables; | |
using UnityEngine.Timeline; | |
public class SignalReceiverWithString : MonoBehaviour, INotificationReceiver | |
{ | |
public SignalAssetEventPair[] signalAssetEventPairs; | |
[Serializable] | |
public class SignalAssetEventPair | |
{ | |
public SignalAsset signalAsset; | |
public ParameterizedEvent events; | |
[Serializable] | |
public class ParameterizedEvent : UnityEvent<string> { } | |
} | |
public void OnNotify(Playable origin, INotification notification, object context) | |
{ | |
Debug.Log("OnNotify called with notification: " + notification.GetType().Name); | |
if (notification is ParameterizedEmitter<string> stringEmitter) | |
{ | |
var matches = signalAssetEventPairs.Where(x => ReferenceEquals(x.signalAsset, stringEmitter.asset)); | |
foreach (var m in matches) | |
{ | |
m.events.Invoke(stringEmitter.parameter); | |
} | |
} | |
} | |
} | |
public class ParameterizedEmitter<T> : SignalEmitter | |
{ | |
public T parameter; | |
} | |
public class SignalEmitterWithString : ParameterizedEmitter<string> | |
{ | |
} | |
[TrackClipType(typeof(SignalReceiverWithString))] | |
[TrackBindingType(typeof(SignalReceiverWithString))] | |
public class SignalReceiverWithStringTrack : TrackAsset { } |
WARNING!! Unity 6 Timeline doesn't seem to like the TrackAsset
... when you set it up, it works, but then, sometime later, and for no apparent reason, the track is disabled and has a warning symbol on it. The signals you added will also be gone. The solution is to just use a normal Signal Track but make sure you also add a Signal Receiver component to the binded object that also has your custom receiver on it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this script to an object that you want to receive signals. Then add a Timeline track called
Signal Receiver With String Track
. Add the object you added the script to as the binding on the Timeline track. Now you can right-click in the track and add aSignal Emitter with String
to the track. This is theSignal
that has an addedparameter
that is astring
type. You can easily adapt this to include other types of Signals. Best to separate out this into classes and create other types.