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?
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
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 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