"Animation state could not be played because it was not found"
I have a java script that is supposed to make a gameobject appear and play an animation when you collide with a trigger, but i always get the error "Animation state could not be played because it was not found"
here is my script:
var monster : GameObject;
var monster2 : GameObject;
var playerTag = "Player";
function OnTriggerEnter (col : Collider) {
if(col.tag == playerTag){
monster.GetComponent.<SkinnedMeshRenderer>().enabled = true;
GameObject.Find("ghoulprefab").GetComponent.<Animation>().Play("surface");
yield WaitForSeconds(2.16);
GameObject.Find("ghoulprefab").GetComponent(EnemyAi).enabled = true;
GameObject.Find("ghoulprefab").GetComponent(EnemyHealth).enabled = true;
GameObject.Find("ghoulprefab").GetComponent(Animator).enabled = true;
}
}
How can this be fixed??
Answer by arbazgillani · May 18, 2016 at 02:23 PM
Animation component is not attached to the gameobject. Please attach it ur problem would be sorted.
Answer by Ego65 · Oct 06, 2016 at 05:47 PM
I had the same prob because i did add a animation component !
But that is part of the old legacy anim system. Just add an Animator component to your game object. And in your script attached to it make :
public Animator AvaAnimation; // or however you want to call it
public bool reached = false;
private Vector3 Dist;
void Awake() // my simple example
{
AvaAnimation = GetComponent<Animator>();
AvaAnimation.enabled = false;
}
void Update ()
{
if(thisgameobj.activeSelf)
{
Dist.z = targetpos.z - thistransform.transform.position.z;
if(Dist.z <= 0.1f)
{
reached = true;
}
if(!reached)
{
MoveForward(); // animation wont play
}
else
{
if(reached) // bool (your condidtion)
{
AvaAnimation.enabled = true; // animation starts
}
}
}
}
Drag your game object which shall be animated in the Controler field in the animator component.
Then drag your game object in the public Animator field in the script. In my case all works fine and i hope this is helpfully for any other beginner as i am :)
Answer by mirzamzn1 · Feb 02, 2020 at 10:20 AM
please help me
The animation state Moveto could not be played because it couldn't be found! Please attach an animation clip with the name 'Moveto' or call this function only for existing animations. UnityEngine.Animation:Play(String) Ulti:MoveTo(GameObject, Vector2, Single) (at Assets/Scripts/Play/Ulti.cs:48) GameController:RuleChecker(GameObject, GameObject) (at Assets/Scripts/Other/GameController.cs:153) GameController:JewelSelecter() (at Assets/Scripts/Other/GameController.cs:99) GameController:Update() (at Assets/Scripts/Other/GameController.cs:70)
Your answer
Follow this Question
Related Questions
Animation Types Won't Play 0 Answers
Trying to get animation to work. Problem with JS. 1 Answer
Idle , Move and Attack animations 0 Answers
Where to put ; 2 Answers
GetAnimatorTransitionInfo(0).IsName("Any State -> otherStateName") 0 Answers