- Home /
Switching Animator on/off
Hi everybody! I have a character, controlled by mechanim animator+script. I'd like to have an opportunity to switch animator off and then to switch it on. The first issue is easy, but I haven't managed to implement the second one yet. I tried just to set the 'enabled' property to 'true' from the script. I also tried to make an animation state with an empty mask. But all these things don't work properly. The animator remains disabled.
By the way, I need this to switch between a pure ragdoll and an animation-controlled character. So I thought about making some kind of a switcher: ragdoll on - animator off / ragdoll off - animator on.
Thanks beforehand for help.
Welcome!
From your somewhat vague description of the problem, I'm thinking you're trying to turn it back on from inside Update or something, which doesn't run when you disable a GameObject/script.
If thats not the case, it would be helpful if you provide code.
Sorry for the bad description.
I have two methods inside the animation controller class: $$anonymous$$ill() and Resurrect(). The first one simply searches for all the children's colliders and rigidbodies (the ragsoll structure) and switches them on like that:
collider.isTrigger = false;
body.is$$anonymous$$inematic = false;
It also switches off the animator and the character controller:
_animator.enabled = false;
GetComponent <CharacterController> ().enabled = false;
At last, it sets the 'bool _disabled' variable of the animation controller script to 'true', but doesn't disable the script, actually. Resurrect() makes precisely the opposite things.
And here is the 'Update' method:
void Update ()
{
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.$$anonymous$$) && _disabled)
Resurrect ();
if (RPGCamera._instance.enabled && !_disabled)
{
HandlePlayerInput ();
CalculateAnimatorParameters ();
if (_needAlign)
AlignTorsoToCamera ();
}
}
Inside 'HandlePlayerInput' we find:
private void HandlePlayerInput ()
{
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.$$anonymous$$))
$$anonymous$$ill ();
It seems to be correct. At least, the script remains enabled. By the way, I also tried to implement the 'Resurrect()' method in another script - this made no difference.
P.S. In the question nearby I've seen guys using the following construction:
animator.enabled = !activeRagdoll ;
I wonder, if it works correct...
Your answer
Follow this Question
Related Questions
how to stop animator? 4 Answers
Animator overriding collisions? 0 Answers
Blending Animator Animations with Ragdoll 2 Answers
Using Ragdoll on character with mecanim animator 2 Answers
Mecanim and Ragdoll Issues? 2 Answers