Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question how to delete notification and receiver?

Discussion in 'Timeline' started by yanfei_game, Jul 27, 2023.

  1. yanfei_game

    yanfei_game

    Joined:
    May 15, 2017
    Posts:
    26
    I know that unity timeline have interface below:
    Code (CSharp):
    1. PlayableOutput.AddNotificationReceiver
    2. TimeNotificationBehaviour.AddNotification
    they accept time parameter both.
    They work on editor mode, but unfortunately I did not find any interface about [deleting] notification.
    Why I need these interface?
    1 I want trigger event on every clip at begin or end by code, and I don’t need do it by adding marker on timeline editor manually.
    2 I wish to loop at specific clip.
    3 I do not want to create a notification every time for reducing gc.
    any help, please.
     
    Last edited: Aug 2, 2023
  2. tsukimi

    tsukimi

    Joined:
    Dec 10, 2014
    Posts:
    76
  3. yanfei_game

    yanfei_game

    Joined:
    May 15, 2017
    Posts:
    26
    Thanks for reply. The output can remove the receiver, But one receiver will be invoke by many notification. I will not receive the other notification if I remove the receiver. so it would be perfect if I could remove nofifications on the behaviour. I still can't find any interface on the behaviour that can remove nofications.
     
  4. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    125
    I also can't find any deleting function too; another solution is to add a
    IsInvalid
    flag field to all notifications, and when you don't want the notification to be processed, turn the IsInvalid flag on. In the receivers, if the flag of the notification is on, just don't process and return. This implementation also matches your needs that "I do not want to create a notification every time for reducing GC".
     
  5. yanfei_game

    yanfei_game

    Joined:
    May 15, 2017
    Posts:
    26
    I resolve it by create one custom NotificationBehaviour myself. You create one Custom Notification Track, and listen to it's Behaviour interfaces (OnGraphStart, ProcessFrame......). In this way, you take over all of details, so you can get rid of gc.
    Take care of PlayableDirector [Manual] mode. the [ProcessFrame] never be called at last frame. [OnGraphStop/OnPlayableDestroy] never be called under manual mode.
     
  6. yanfei_game

    yanfei_game

    Joined:
    May 15, 2017
    Posts:
    26
    Thanks for reply. It is one solution indeed. I resolve it by create on custom notifcation track currently, and it give me more flexibility.
     
  7. yanfei_game

    yanfei_game

    Joined:
    May 15, 2017
    Posts:
    26
    You will find that TimeNotifycationBehaviour of unity create one new list of notification every time playable created if you dig into the code. It seems that you have to create your own notication behaviour to avoid this case.
    It will be OK in the most of case because a timeline play several seconds, gc only happen at beginning.
     
    Yuchen_Chang likes this.