How can I trigger a custom method for a custom script?

I’m trying to figure out how I can attach a custom method onto a game object, and then trigger that method from the Three.js scene (in App.tsx). So I’ve attached a custom script (.ts file in scripts which generates a C# stub I can attach to a game object), to a game object. Instead of just using the built-in functions (e.g. start, update), I want to make a custom method that can be triggered which does a specific animation. Then in my App.tsx I want to be able to trigger that custom method, say, on a button press.

I was having trouble finding docs on this – does anyone know how to do that?

Original Post on Discord

by user 690021744479830061


Just on the phone right now so i cant send detailed code examples but here is how you could play the animation using the animation component or how to reference animation clips if you want to play them with your own animationmixer: Script Examples | Needle Engine Documentation

Let me know if that already helps

Thanks! I’m actually not using an animation mixer – I’m wanting to animate with Three.js directly. Where is the docs on that?

by user 690021744479830061

It looks like in all these examples it’s invoking the method from within the C# or custom script code. I want to invoke it from outside of Unity/the scene completely. I’m invoking it from some html that overlays the whole thing

by user 690021744479830061

By animating with threejs directly you mean you don’t use animation clips and just modify/animate the properties from code?

The samples contain a small example for interop with external js.
Needle Engine Samples and click on download samples. I think it is called Javascript Interop. It works the same as with any javascript module basically where you import the types and use them (e.g. you can make a static singleton getter too, depends on your usecase)

You can also use the NeedleEngine.registerCallback events for example to get hold of the threejs scene and query components with the GameObject.getComponentInChildren methods for example. Maybe take a look at Needle-engine - Vite Template (forked) - StackBlitz