Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Timeline custom signal, the receiver still needs 'normal' signal receiver attached too

Discussion in 'Timeline' started by Ziplock9000, Jul 17, 2023.

  1. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    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

    Code (CSharp):
    1. public class ParameterizedEmitter<T> : SignalEmitter
    2. {
    3.     public T parameter;
    4. }
    5.  
    6. public class SignalEmitterWithString : ParameterizedEmitter<string> { }
    7.  
    8.  
    9. public class SignalReceiverWithString : MonoBehaviour, INotificationReceiver
    10. {
    11.     public SignalAssetEventPair[] signalAssetEventPairs;
    12.  
    13.     [Serializable]
    14.     public class SignalAssetEventPair
    15.     {
    16.         public SignalAsset signalAsset;
    17.         public ParameterizedEvent events;
    18.  
    19.         [Serializable]
    20.         public class ParameterizedEvent : UnityEvent<string> { }
    21.     }
    22.  
    23.     public void OnNotify(Playable origin, INotification notification, object context)
    24.     {
    25.         if (notification is ParameterizedEmitter<string> stringEmitter)
    26.         {
    27.             var matches = signalAssetEventPairs.Where(x => ReferenceEquals(x.signalAsset, stringEmitter.asset));
    28.             foreach (var m in matches)
    29.             {
    30.                 m.events.Invoke(stringEmitter.parameter);
    31.             }
    32.         }
    33.     }
    34. }
    What am I missing?
     
  2. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    39
    Code (CSharp):
    1.     [TrackClipType(typeof(SignalReceiverWithString ))]
    2.     [TrackBindingType(typeof(SignalReceiverWithString ))]
    3.     public class SignalReceiverWithString : TrackAsset {}
    This seems to add it to the track and works with the binding.
     
  3. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    So dump inheriting from MonoBehaviour, INotificationReceiver? Just that even the official examples use those?
     
  4. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    39
    Oops my bad! Should be a new class

    Code (CSharp):
    1. [TrackClipType(typeof(SignalReceiverWithString ))]
    2.     [TrackBindingType(typeof(SignalReceiverWithString ))]
    3.     public class SignalReceiverWithStringTrack : TrackAsset {}
     
  5. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    Ok, what happens with this new class? Unity will just automatically use it when creating a new track of the 'WithString' types?
     
  6. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    39
    Yeah - Unity seems to pick up any extension of the TrackAsset as an option for a new track. You can bind the matching type to the track then.
     
    tsukimi and Ziplock9000 like this.
  7. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    Thanks. I'll try this out.