Hi,
I am simply trying to get an animation state to change via mechanim, and I cannot get it to work. I can access the animator component, and toggle its enabled/disabled state, but when I use “setTrigger”, it doesn’t trigger the mechanim state to change.
I have a character that is Idle. There is a trigger condition “Walk” setup on the transition from Idle->Walk, but it never changes when called from my script. Am I doing something stupid? Calling “.play(“Walk”)” works, but setting the trigger does not.
`import { Animator, Behaviour, serializable, serializeObject, GameObject } from “@needle-tools/engine”;
import { Object3D } from “three”;
export class AnimatorExample extends Behaviour {
@serializable(Animator)
public personAnimator?: Animator;
start()
{
if (this.personAnimator) {
this.personAnimator.setTrigger("Walk");
}
}
Hey @kipash Thank you for your response. Im not sure what the issue was. I checked spelling and all was correct. I deleted the animator controller and re-made it and it was fine then.
I have since modified the script and am now facing an error when trying to run .setTrigger() on multiple animators in an array. Can you please advise on why I get the error “.setTrigger is not a function”. In Unity, I have an array with 6 animators assigned. Is it something to do with how I am initially declaring the array?
`import { Animator, Behaviour, serializable, serializeObject, GameObject } from “@needle-tools/engine”;
import { Object3D } from “three”;
export class RaceStarter extends Behaviour {
@serializable(Animator[6])
public horseAnimators?: Animator[];
@serializable(Animator)
public raceAnimator?: Animator;
start()
{
console.log("RaceStarter start");
this.raceAnimator?.setTrigger("StartRace");
//start all horses
if (this.horseAnimators) {
for (let i = 0; i < this.horseAnimators.length; i++) {
this.horseAnimators[i].setTrigger("StartRace");
}
}
}