I’ve set up a custom signal, with an emitter and a receiver and it works just fine to pass a string.
However the endpoint receiving object not only requires the custom receiver (as expected) but also needs the default Signal Receiver on it which doesn’t even get ‘used’ as it can’t work with custom data.
However, without the latter the timeline loses it’s reference to the target object.
My emitter inherits from SignalEmitter and my receiver from MonoBehaviour, INotificationReceiver
public class ParameterizedEmitter<T> : SignalEmitter
{
public T parameter;
}
public class SignalEmitterWithString : ParameterizedEmitter<string> { }
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)
{
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);
}
}
}
}
[TrackClipType(typeof(SignalReceiverWithString ))]
[TrackBindingType(typeof(SignalReceiverWithString ))]
public class SignalReceiverWithString : TrackAsset {}
This seems to add it to the track and works with the binding.
[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.
Gutted. This seems too buggy to use.
The error is an editor error when it tries to add the custom signals to the track. They don’t show, but if you run the scene they appear in play mode. If you then stop playing the scene, they are there on the track again.
Unfortunately, this sometimes just happens randomly when you are loading scenes.
Can you guys confirm that you have been using this successfully? I think my code is slightly different to yours. Here it is:
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 { }
No worries. I think this is a bug with Unity 6. Would love to get an engineer involved to see if we can resolve this. Custom Signals are SOOO useful, and they could really make a feature out of this.