Changing Characters While playing(Animator)

Hey guys, I’m making a game and now i need to change some characters while playing. for example while user is playing if it clicks an option that character should change and another character should take its place with same animator.

I can change characters but I Can’t use same animator in that character. lets say x character is running and if player presses stop y character should be transported to x’s location and by using the same animator i should be able to change its animation from running to idle (my code is working for one character)

So Far I have tried this code and it should work in theory like i said actually it does change characters locations and makes X variable Y but its not triggering animator

        X.transform.position = new Vector3(200, 200, 200);
        X = GameObject.Find("Y");
        anim = X..GetComponentInChildren<Animator>();
        anim.SetTrigger("Idle");

ah, i think i misunderstood your problem (my original answer is below). If both characters already have an Animator component, and if the last line isn’t throwing an exception, try ensuring that the Animator on Y game object is enabled, and check the state of the Animator in the Animator window, ensure that there’s and “Idle” trigger configured and that it’s set to true.

original answer - but may have misunderstood

If your characters are essentially the same (they use the same rig/model/avatars), then you can create an empty game object and then add an Animator component to it, configure the Animator, and then save that game object as a prefab, and then instantiate it and add it to the new char (if it’s not already added). This requires coding, but just a little.

But, if you’re trying to re-use the same instance, my guess is that’s probably not going to work out because Animators maintain internal “States”, and moving an Animator to another character would likely make all of these “States” invalid and thus break the animation.

If the characters use different rigs/models, you probably don’t want to re-use an animator instance or configuration/prefab though, because each animation clip should probably be “retargeted” to/for each different character. My recommendation is to do the painful work of setting up and configuring an animator for each character. If you have dozens or hundreds of different characters, but that use the same rig, the definitely use the first suggestion of the Animator game object prefab.