- Home /
LocomotionSystem not working in Unity 5
I'm fairly new to scripting and I'm trying to test the Locomotion System asset in Unity 5 so I can use procedural animations in my project, but when I hit play the legs don't animate and I get these error messages:
The lines in the LegController script creating these errors are as follow (respectively):
.........................
(LegAnimator.cs line 254)
controlMotionState.enabled = true;
.........................
(LegAnimator.cs line 390)
MotionGroupState group = motionGroupStates[g];
........................
(LegAnimator.cs line 1889)
switch (legState.phase) {
........................
I couldn't get the character to move using the NormalCharacterMotor script, so I wrote my own movement script which works fine:
using UnityEngine; using System.Collections;
[RequireComponent(typeof(CharacterController))] public class movement : MonoBehaviour {
Vector3 direction = Vector3.zero;
void Update ()
{
CharacterController controller = GetComponent<CharacterController>();
direction = new Vector3(Input.GetAxis("hori_left_stick"),0,Input.GetAxis("vert_left_stick"));
controller.Move(direction);
}
}
...................
Other than the movement script, everything is set up according to the documentation. The Animation component is attached and contains the all the animations including the ones I'm targeting ("idle1" and "walkForward"). I've searched and searched but haven't found a relevant answer. Is this some sort of Unity 5 compatibility issue?
Oh yes it would be great if the locomotion system will be fixed for Unity 5. When I tried it last time even the default demo scene where the man is walking around was behaving very strange.
That currently keeps me from switching over to Unity 5. Alternatively I would need to learn how to move a legacy 4 leg animal with mecanim, I failed to get it working.
Answer by domini · Jun 21, 2015 at 11:15 AM
OK, as nobody else answered, I started to have a look myself ;)
... and here are my first results.
The problem is the animation system. Unity 5 REQUIRES to mark "LEGACY ANIMATION" as such.
So you need to change the two commands where the "DUMMY ANIMATION" is created and mark them explicitly as legacy like this:
Near Line 254:
// Create dummy animation state with control motion name
//GetComponent<Animation>().AddClip(new AnimationClip(), "LocomotionSystem");
AnimationClip newAnim = new AnimationClip();
newAnim.name = "LocomotionSystem";
newAnim.legacy = true;
GetComponent<Animation>().AddClip(newAnim, "LocomotionSystem");
Near Line 285:
// Create dummy animation state with motion group name
//GetComponent<Animation>().AddClip(new AnimationClip(), legC.motionGroups[g].name);
AnimationClip newLegCAnim = new AnimationClip();
newLegCAnim.name = legC.motionGroups[g].name;
newLegCAnim.legacy = true;
GetComponent<Animation>().AddClip(newLegCAnim, legC.motionGroups[g].name);
Hi, sure, I added my script, there are some more modifications than mentioned here, mainly because I had some problems with editor play mode. For some reason I cannot upload it here directly so I had to upload it elsewhere:
Hi guys, I know this is a thread written 4 years ago but I can't find any proper solution for exactly your issues even in late 2019... Did you manage to get the Locomotion system running? The legacy animation seem no longer to be valid as it deletes those if you drag and drop them into the animation slots (for animation groups) when pressing Play. And in fact they don't even appear as selection options in the editor...
Answer by kfirmon · Nov 25, 2015 at 03:15 PM
I'm working with Unity 5.2.2f1 and I had to do it this way: Line 251: // Create dummy animation state with control motion name //GetComponent().AddClip(new AnimationClip(), "LocomotionSystem");
AnimationClip newAnim = new AnimationClip();
newAnim.name = "LocomotionSystem";
newAnim.legacy = true;
GetComponent<Animation>().AddClip(newAnim, "LocomotionSystem");
controlMotionState = GetComponent<Animation>()["LocomotionSystem"];
and then Line 287: // Create dummy animation state with motion group name //GetComponent().AddClip(new AnimationClip(), legC.motionGroups[g].name);
AnimationClip newLegCAnim = new AnimationClip();
newLegCAnim.name = legC.motionGroups[g].name;
newLegCAnim.legacy = true;
GetComponent<Animation>().AddClip(newLegCAnim, legC.motionGroups[g].name);
controller = GetComponent<Animation>()[legC.motionGroups[g].name];
hope this helps ;)
Answer by muzboz · Nov 18, 2016 at 07:44 AM
Thanks for the tips guy... It also spat a few errors about Horizontal2, Vertical2 and Sneak not being set up in the Input Manager. I just duplicated Horizontal and Vertical, and renamed them with the "2" on the end. And I duplicated Fire and called it "Sneak", and it all worked!