I’m just starting to try out the scripting a bit. I have a file “AnimationSystem.ts” under src/scripts, the component that is generated from it is connected to a button. But as soon as I call it an error occurs:
Uncaught TypeError: this.animator.SetFloat is not a function
The Code of the AnimationSystem.ts is the following:
import { Animator } from "@needle-tools/engine";
import { Behaviour } from "@needle-tools/engine/engine-components/Component";
export class AnimationSystem extends Behaviour
{
animator : Animator;
start(){
console.log("Initialize Animation System");
}
TriggerAction(){
this.animator.SetFloat("Time", 1);
}
}
Of Course the Animator is referenced under the Inspector Field: animator
Original Post on Discord
by user 260813948499132416
marcel
(marwi)
October 3, 2022, 12:00am
2
You need to mark your animatorfield with @serializeable (Animator) so that at runtime the animator reference can be resolved and assigned
marcel
(marwi)
October 3, 2022, 12:00am
3
The Attribute is also exported in @needle-tools /engine i think
thankyou for the fast response . Now i got another error with the serializeable line.
import { Animator } from "@needle-tools/engine";
import { Behaviour } from "@needle-tools/engine/engine-components/Component";
export class AnimationSystem extends Behaviour
{
@serializeable(Animator)
public animator? : Animator = undefined;
start(){
console.log("Initialize Animation System");
}
TriggerAction(){
if(this.animator != undefined){
this.animator.SetTrigger("Trigger");
} else {
console.log("Animator is undefined");
}
}
}
The error now says
AnimationSystem.ts:7 Uncaught ReferenceError: serializable is not defined
at AnimationSystem.ts:7:12
by user 260813948499132416
ah
by user 260813948499132416
i have to import serializeable from @needle-tools /engine
by user 260813948499132416
Thank you for the quick help. the fun with the needles continues.
by user 260813948499132416
Completely different question for which I do not necessarily want to open a new post: Is it possible to display a HTML element inside a 3D scene in needles. So for example that you embed a HTML form or even an iframe on a 3D plane?
by user 260813948499132416
marcel
(marwi)
October 3, 2022, 12:00am
11
Oh wow it’s indeed possible. there’ s a lot that can be made out of it.
by user 260813948499132416