Thanks a lot @seant_unity for the quick and comprehensive reply
I tried your example with the “Scene Offsets” mode, but it wasn’t very clear what value I should set for the ‘positionOffset’.
I tried the animated object position and local position, but it was giving me some weird results.
But when I changed the offset mode to “Apply Transform Offsets” and set the ‘positionOffset’ to the local position, it worked perfectly (same thing for rotation also).
But then I didn’t like that the reflection solution would generate garbage because of the boxing, so I modified the “AnimationTrack” class, and added a method to do that without reflection.
For whoever is interested, here’s how I did it:-
-
In the timeline package folder, go to the file “Runtime\Animation\AnimationTrack.cs”
-
Add an AnimationOffsetPlayable field to the class “AnimationTrack”
AnimationOffsetPlayable cachedOffsetPlayable;
- Find the method “ApplyTrackOffset”, and modify it as follows
//find this line in the method
var offsetPlayable = AnimationOffsetPlayable.Create(graph, pos, rot, 1);
//add this line after it
cachedOffsetPlayable = offsetPlayable;
public void ResetTransformOffset(PlayableDirector director) {
if (cachedOffsetPlayable.IsValid()) {
//get the bound animator object transform
var animatorTransform = GetBinding(director).transform;
cachedOffsetPlayable.SetPosition(animatorTransform.localPosition);
cachedOffsetPlayable.SetRotation(animatorTransform.localRotation);
}
}
- Now in you code, whenever you want to play the timeline you can write the following (Note the track should be in “Apply Transform Offsets” mode)
AnimationTrack animationTrack = (director.playableAsset as TimelineAsset)
.GetOutputTracks()
.OfType<AnimationTrack>()
.FirstOrDefault(track => track.name == "track name");//based on track name, or whatever filter you prefer
animationTrack.ResetTransformOffset(director);
Thanks again @seant_unity for pointing me in the right direction, please feel free to correct me if anything I mentioned is incorrect
Side question / request
any chance of adding such API, so I don’t have to apply my modification every time I want to update the timeline package?