Animator.SetFloat(String, Number)

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

You need to mark your animatorfield with @serializeable(Animator) so that at runtime the animator reference can be resolved and assigned

The Attribute is also exported in @needle-tools/engine i think

thankyou for the fast response :pray:. 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

Yes :slightly_smiling_face:

Thank you for the quick help. the fun with the needles continues. :cactus:

by user 260813948499132416

:slightly_smiling_face:

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

I think there is a small sample script in here that might help getting started

https://github.com/needle-tools/needle-engine-samples/blob/main/package/Runtime/Needle%20Engine%20Samples~/HtmlMesh.ts

Oh wow it’s indeed possible. there’ s a lot that can be made out of it. :thinking:

by user 260813948499132416