- Home /
2D animations - same controller for different characters
Hi,
I have several playable characters, that use the exact state machine for the animations, but the animations themselves are different (different sprites). I was wondering if there was a way to use a single animation controller for all these characters, instead of duplicating it and changing the "motion" component of each state?
Thanks
Answer by Tomer-Barkan · Mar 12, 2015 at 01:49 PM
Half a year later I can answer my own question. Not sure when this feature was added, but there's now a Animator Override Controller component which can be created in the project. This allows you to select an animator controller (state machine), and set different animations for each state, but maintain the same transitions and properties.
Neat.
Hey $$anonymous$$er, I've done an asset that could also help people with this kind of problem. It help me so much with me game development. It duplicates an animator and then replace all clips automatically. States and transitions are kept during transfer.
You can even copy events and curves even if clips have different durations.
I'll just link an example video with a 2D characters : Example
General presentation with events and curves : Presentation
I had a few of these tools too, but the big problem is that if you want to change something, you need to change it all now. Anyway, like I said the AnimatorOverrideController does the trick so no need for any hacks anymore.
Answer by KMKxJOEY1 · Jul 11, 2014 at 01:35 PM
No, I'm pretty sure you need to have a different controller for each animated object. Like you said, each state in a controller is linked to 1 motion/animation slot
Answer by ruby589 · May 17, 2016 at 12:38 PM
No!Different controller for each animated object maybe better!
Answer by N1NNIE · Dec 31, 2020 at 12:36 PM
I watched a brackeys video about animations and I put in a piece of the code and gave me tons of errors. Can you help why this is happening. Here is the code:
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
Also, it said theres something wrong with the equal sign and type errors. Its a hideous blur. If you want the entire code here: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour { public CharacterController2D controller; public Animator animator;
public float runSpeed = 40f;
float horizontal$$anonymous$$ove = 0f;
bool jump = false;
// Update is called once per frame
void Update()
{
horizontal$$anonymous$$ove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", $$anonymous$$athf.Abs(horizontal$$anonymous$$ove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate()
{
controller.$$anonymous$$ove(horizontal$$anonymous$$ove * Time.fixedDeltaTime, false, jump);
jump = false;
}
}
Your answer
Follow this Question
Related Questions
How to make a proper walk animation cycle? 0 Answers
,Is there a Way to Flip 2D-Keyframes? 0 Answers
how to make 2D sprites skeletal Movements 1 Answer
2D Animations Not Working After Building Game 1 Answer
First Frame of 2D Animation Ignored? 0 Answers