Controlling the timeline start position of events

For example, we are now playing the BGM A. Now when player enter a new scene, we will then switch to BGM B, and after he finish the objective in that scene, we will switch back to BGM A. Suppose we want to play BGM A just from where we last ended, according to this topic, we can save the playback position manually, then call EventInstance::setTimelinePosition.

Does that means, for every track we would like to realize the function above, we need to start the instance manually?

Because currently in our project, we swtich different BGM by putting the instances in a parameter sheet and then set parameter when needed, rather then create and play instances by event paths. This approach save the efforts
of managing events paths.

To summary our question:

  1. Is calling EventInstance::setTimelinePosition the only way to controll the playback position of a tack? Is there any other approach to implement out demand?
  2. Is it possible to set playback position when switching active instance in parameter sheets? Does parameter sheet destroy and create instance every time the switch happens?

Appreciated so much
(would like to see some related topics)

If you want to be able to pause your game’s music and then unpause it again later without starting it over from the beginning, and also want to use this method of selecting which track to play, there’s a way to do it.

You’ll need to create two instances of the parent event that uses a parameter to select which music track should play; I’ll call these “the A instance” and “the B instance.” Pause the B instance (using Studio::EventInstance::setPaused immediately upon starting it, and allow the A instance to play.

When you want to pause the music that’s currently playing and begin playing a different track, set the parameter of the B instance to the parameter value corresponding to the new music you want to play, then pause the A instance and unpause the B instance (again by using Studio::EventInstance::setPaused). This will cause the B instance to begin playing the new track.

When you want to stop playing the new track and resume the old track, pause the B instance and unpause the A instance. This will cause the A instance to resume playing from the point it was paused at.

Paused event instances are automatically virtualized, and thus consume only a negligible amount of resources.

Yes and no. In order to call EventInstance::setTimelinePosition on an event instance, that instance must exist, and therefore must have been created. However, it is not necessary to create a new instance purely so that you can call EventInstance::setTimelinePosition on it; if an instance exists already, you could call it on that instance.

In any case, the method I described in that other thread was for starting music that had not previously been playing in the player’s local instance of the game. In your case, you want to resume playing music that had already been playing before being paused, which makes pausing and unpausing the event instance more appropriate than using EventInstance::setTimelinePosition on a new instance of the event.

No. It is also possible to set the timeline position of an event by using logic markers; and every instrument has a “start offset” property that determines how far through the asset the asset begins playing from when that instrument is triggered, making it possible to start from part-way through an asset without using the timeline playback position at all.

That being said, none of these methods will be necessary if you pause and unpause the event instance as I suggested above.

Yes. The method I described above should work.

No. It is not possible to get or set the timeline playback position of an event instance spawned by an event instrument or command instrument. If you want to get or set the timeline playback position of an event instance, the event instance must be spawned by your game’s code.

Fortunately, the method of pausing and unpausing events that I described above does not require you to get or set the timeline playback position of any event instance.

Yes and no.

Whenever an event instrument is triggered, it spawns a new instance of the event it references. Each such new event instance is completely independent of any other instance of that event that may have been spawned previously.

When an event instrument is untriggered, it may or may not destroy any currently-playing instance of the event instance associated with that instrument. Whether it does depends on the instrument’s settings, and on the content of the associated event.

1 Like