Multiple animators use the same controller / sate-machine or how to sync them?

This seems simple but I can’t get it to work out…

I need multiple animators that all use the same controller asset, to have their state machines be synchronized, regardless of if they are enabled or not.

I almost need a “global” state machine that any instance of this animation reads from, but I don’t know how to do it.

I have a system that creates a level out of prefabs. Each prefab contains 3 copies for the same fbx(model and animation). They all use the same Animator Controller aka Animator State-Machine.

However, because each has it’s own unique animator component, and apparently it’s own instance of the state machine, I’m running into trouble.

I can track and access all of my animators to set triggers on each one, however not all of their objects are on at the same time. So I can synchronize all the state machines that are on at the same time, but when new ones turn on, they are in their default “idle” state.

You can use This method. With this you can set the animation state start time, than any time you enable new component you will sync its animation with current. Maybe you will need to have some global timer to know where you animation is at the moment which would reset everytime animations makes a loop (can use an animation event for that).

I could see this being done through a StateMachineBehavior script using the SharedBetweenAnimatorsAttribute (Documentation on this can be found Here) Although it is intended to reduce the memory footprint it also seems to be capable of doing what you are looking for. You would attach the behavior script to the default start state and it could look something like this (untested):

using UnityEngine;
using System.Collections;

public class SyncBehav : StateMachineBehaviour {

	//Used to sync
	public Animator masterAnimatorComponent;
	// OnStateEnter is called when entering a state
	override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex){
		//I am sure this can be placed somewhere else but for demo purposes it's here
		if (!masterAnimatorComponent) {
			masterAnimatorComponent = animator;
		} else {
			//Sync any required params, states or clips here.