How to start scripting? where to write the script? and how to connect it with unity?

I’m not a coder and i use playmaker to work in unity, but i see that chatgpt is a good way to get your code done, so i wanted to know how to start so i can try few things with chatgpt.

Original Post on Discord

by user 546555823451668481

Have you read the docs at Needle Engine Scripting | Needle Engine Documentation - it contains the infos for getting started

yes i have been through it but i really dont understand on how to start.

by user 546555823451668481

does the TS automatically creates a C# script?

by user 546555823451668481

You open the vscode workspace and create typescript files in src/scripts. There are examples components in the docs and also in the samples that you can download :slightly_smiling_face: when you save the typescript file the component compiler in unity should generate a matching csharp mock component that you can attach to the objects in your scene

It should, some people are reporting that it doesnt do it for them in which case you can also create it manually (it just needs to have the same name and fields as your typescript class). The console in unity also logs the command it uses to generate it. Theres an active post in the forum about that issue. But it usually works like that.

so i have this test script

by user 546555823451668481

class MyCustomComponent extends Component {
speed = 0;

rotate(angle: number) {
// …
}

update(deltaTime: number) {
this.transform.rotate(this.speed * deltaTime);
}
}

registerComponent(MyCustomComponent);

by user 546555823451668481

now if i create a file on vscode then does it need to have same name as class name?

by user 546555823451668481

That will not work, please see the reference in Needle Engine Scripting | Needle Engine Documentation. The class needs to subclass behaviour, the method is update(){} and this.transform doesn’t exist. Looks like gpt has produced you some unity code. You also dont need to call registerComponent (thats done automatically be the exporter and the methos doesnt exist like that)

The class name and the filename dont need to match

Ok thanks

by user 546555823451668481

You can also find some more code examples in the samples repository. Its linked at Needle Engine Samples - hope it helps you

Every scene you find there can be downloaded with all code included