Forum rules - please read before posting.

OnEnterTimeline event is only fired when starting the Timeline through the Control Timeline Action

Hi Chris,
It's basically as the title says, the OnEnterTimeline event is only fired when starting the Timeline through the Control Timeline Action, and even that isn't that reliable always. For example if I spawn a timeline on scene start an play it right after with the action, it's not fired.
Is that the correct behaviour? what could I do to fire the event whenever a character is in a timeline, independent of how the timeline is started?

Cheers,
Onat

Comments

  • Oh fyi, I think these events are also missing in the scripting api (if i didn't overlook something...)

  • Further investigating the reliability issue revealed, that a little wait between instantiating and starting the timeline helps, so I assume that by the time I wanted to start the timeline, the prefab wasn't correctly initialized yet (which still kind of worked, but didn't fire the event..), wouldn't something like "wait until finished" in the object: add action make sense for things like that? If not, what would be the best way to make sure that things are properly initialized, before the al continues?

  • The events will only fire when using the provided Engine: Control Timeline Action, because that is the only way that AC can detect this reliably. If you're running through other means, e.g. custom script, you shouldn't need a custom event hook since you're in control of when it's started anyway.

    a little wait between instantiating and starting the timeline helps, so I assume that by the time I wanted to start the timeline, the prefab wasn't correctly initialized yet

    It's hard to pinpoint the root cause for this. Try inserting an Engine: Wait Action with a Wait time (s) set to -1. If a negative value is supplied, the Action will wait exactly one frame - which may be enough for the Timeline to become properly initialised.

    Oh fyi, I think these events are also missing in the scripting api (if i didn't overlook something...)

    Thank you, it seems these are being left out of the API generator - I shall look into it.

  • Oh great, thanks for the info, the "-1" should be in the manual as pro-tip, that sounds really useful :) Going to try it out now.
    Regarding the Event: that makes sense, and during the normal gameplay I actually always start timelines with the action. The thing is, that I usually edit timelines in Play mode, and I don't always want to start them with the action just for editing purposes. Since our Character controller listens to the event (otherwise it overwrites the timeline animation), I wanted to ask if there is a way to manually fire the event. (for example i could have a script on the playable director that fires the event whenever i play the timeline.)

  • It's not a pro-tip, but it is mentioned in the Manual's "Standard Actions" chapter.

    Thanks for the explanation. You can still trigger an event manually through script, if you want to attach a listener that checks if the Timeline has started playing - though bear in mind it'll then get triggered twice if you run it via Action.

    This is the code that the Action uses to trigger the event. Ultimately it's just calling the Char script's OnEnterTimeline function, but some extra is needed to set up the parameters:

    TimelineAsset timelineAsset = runtimeDirector.playableAsset as TimelineAsset;
    if (timelineAsset != null)
    {
        for (int i=0; i<timelineAsset.outputTrackCount; i++)
        {
            TrackAsset trackAsset = timelineAsset.GetOutputTrack (i);
    
            GameObject bindingObject = runtimeDirector.GetGenericBinding (trackAsset) as GameObject;
            if (bindingObject == null)
            {
                Animator bindingAnimator = runtimeDirector.GetGenericBinding (trackAsset) as Animator;
                if (bindingAnimator != null)
                {
                    bindingObject = bindingAnimator.gameObject;
                }
            }
    
            if (bindingObject != null)
            {
                Char bindingObjectChar = bindingObject.GetComponent <Char>();
                if (bindingObjectChar != null)
                {
                    bindingObjectChar.OnEnterTimeline (runtimeDirector, i);
                }
            }
        }
    }
    
  • Great, thanks!! That's exactly the info I needed :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.