Keeping animation timing in sync when changing animations

I have 2 objects, one with a procedurally animated texture with a repeating cycle of 10 seconds. I’m using Time.time to control the timing.

The other object has two 10 second animations, each created with animation curves. The main animation repeats over and over until the second one is triggered, at which point it needs to wait for the first animation to finish, then play the second. When the 2’nd is finished, the 1’st starts playing(and repeating) again. Everything is on 10 second intervals.

My problem is that the animations of object 2 slowly get out of sync with the object 1.

I’ve tried every combination of animation.Play, PlayQueued, with different wrap modes, but the animations keep getting out of sync.

I was hoping the following code would fix the issue but the animations still get out of sync and slowly get worse. For example, the animations starting to play at 10.02, 20.03, 30.05, 40.1 etc…

IEnumerator Start() {
	while(true) {
		yield return new WaitForSeconds(10);
		if(triggered) {
			animation.Play("animation2");
			triggered = false;
		}
		else {
			animation.Play("animation1");
		}
	}
}

Triggering the second animation makes it worse. After a few cycles it starts to get noticeable.

Any ideas what I’m doing wrong?

Thanks

So, after some research, it looks like other people have been having synchronization issues with WaitForSeconds and InvokeRepeating drifting by a few ms. In many cases I suppose this doesn’t make a difference but in my case it starts to become obvious after a while that things are out of sync.

Does anyone have any animation solutions for what I’m trying to accomplish?

Have you tried :
yield return new WaitForSeconds(10f - 0.016f);

Just a guess.

I’ve moved on to other things for the time being; but now I think that this is just an issue in the Unity Editor.