Hi, I have a Unity Scene with some custom C# scripts, and i install needle package and export this scene by needle and then run in browser, and i found all my custom C# scripts not working.
Why? Did i miss something?
Any help will be appreciate.
Hi Ge Lin,
Step-by-step reasoning:
- Unity C# scripts run in the Unity editor and are included in native Unity PC/mobile builds.
- Needle Engine converts your Unity scene to run in the browser using JavaScript/TypeScript, not C#.
- The standard Needle export only supports Needle Engine Behaviours (Typescript scripts) and built-in Unity components that have equivalents in Needle Engine.
- Custom C# scripts logic is not automatically converted or included in the build—you must rewrite your logic as Needle Engine components in TypeScript.
- This ensures your logic will run in the browser.
What you should do:
- Identify which logic needs to run in the browser.
- Re-implement your C# scripts as Typescript-based Needle Engine Behaviours.
- Use this guide for creating new behaviours: https://engine.needle.tools/docs/working-scripts.html
- Place your new scripts in the /documents/scripts folder and attach them to GameObjects in Unity via the Needle component interface.
Tips for next steps:
- Share the specific logic you want to port for code examples.
- If you have errors or logs, paste them here for more help.
Learn more:
- Needle scripting docs: https://engine.needle.tools/docs/working-scripts.html
- Sample projects: GitHub - needle-tools/needle-engine-samples: Live: https://engine.needle.tools/samples 🌵 Needle Engine sample scenes - use as examples and as a reference for learning 😊
What logic from your C# scripts do you need to port? If you can paste a script or describe its function, I can help rewrite it for Needle Engine.
1 replies left - Get a PRO license for more AI replies.
thread_FWOydBjg8ihI8CSgTciJt1Ae
Reply to this post directly if you need further help (bottom right button)
Thanks a lot. How does ts file work with Unity?
Hi Ge Lin,
To explain how a TypeScript (TS) file works with Unity in the Needle Engine workflow:
Plan:
- Unity scene and assets are authoring data.
- Needle Engine exports the scene and converts Needle Behaviours written in TypeScript (TS) into JavaScript for the browser.
- The TS files live outside Unity — in your project folder, typically under the
scripts/
directory. - Unity links the TS files via special Needle Engine components attached to GameObjects.
- During export, Needle Engine includes and bundles the TS files, making the logic run in the browser runtime.
Detailed explanation:
- Your Unity scene includes GameObjects.
- You attach NeedleBehaviour components via Unity’s inspector by specifying the TS script name.
- The TS script exports a class extending
NeedleEngine.Behaviour
. This class contains lifecycle methods likestart()
,update()
. - When you export with Needle Engine, the Unity project exports JSON/GLTF scene data and bundles your TS scripts.
- In the browser, Needle Engine runtime loads your scene data and runs the TS logic via JavaScript, controlling GameObjects and their state.
- Unity itself doesn’t run TS files; it only references them as Needle components.
- You edit TS files in VS Code and reload/export to run changes in the browser.
Here is a minimal TS script example for Needle Engine:
import { Behaviour, updateable } from "@needle-tools/engine";
@updateable()
export class MyBehaviour extends Behaviour {
start() {
console.log("Started");
}
update() {
this.gameObject.position.x += 0.01;
}
}
Attach MyBehaviour
to a GameObject in Unity, then export and run in the browser.
Summary:
- TS behaviour scripts represent logic.
- Unity links them as components.
- Needle Engine exports everything into browser runnable JS.
For more details, see:
- https://engine.needle.tools/docs/working-scripts.html
- Sample TS scripts: GitHub - needle-tools/needle-engine-samples: Live: https://engine.needle.tools/samples 🌵 Needle Engine sample scenes - use as examples and as a reference for learning 😊
Would you like a step-by-step example on setting up a TS script in Unity?
0 replies left - Get a PRO license for more AI replies.
thread_FWOydBjg8ihI8CSgTciJt1Ae
Reply to this post directly if you need further help (bottom right button)
how could ts script attach to unity gameobject?
Hi ge_lin, I’m sorry but I can’t help you right now. You have reached the maximum number of replies. . Please try again later or get a PRO license for more AI help.
**
Hi, when you put a script (as the bot suggested above) in your web project folder (src/scripts
) a C# script will be generated in Unity which you can attach. We see that the name of your C# script matches with a Typescript class name export class YourScript extends Behaviour
and then export the data inside the glTF files to be used in the web.
Thanks your reply.I have a lot of C# scripts, is there a tool do the reverse job that generate Typescript for C# script?
You can try to start using the AI helper from Unity to translate C# to Typescript/Needle Engine components.
If there’s a C# script found that doesnt has a matching typescript component yet you’ll see this text above the component. You can click it to ask AI about the content and translation. You can also use the context menu of the componen to do the same if you don’t see this text.
Once you get some code you can create a typescript file in your web project and add the component code (in src/scripts
if you’re using our default vite project template)