π§΅#Questions on Splines
You got an error in this <#1024686103598477383> ? π€ what error?
First question: what is the convention of the ~ suffix for ts code? Is that a standard you are using?
ts is the suffix for typescript
Just said unknown error when trying to post π₯²
Strange? Could you try again π
Yah, I know that marcel. More about the ~ suffix on folder
Splines~
Ah sorry I misread. That is so that Unity doesnt import the folder an all the npm node modules
Is that in docs anywhere? Maybe I missed it
So the modules repository contains a package which you can install so you get the npmdef and all that stuff (and the codegen) in your unity project. All npmdefs generate hidden npm packages - but we never want them to be imported by Unity. That's why they are all postfixed with ~
yes see at the bottom at hidden assets: https://docs.unity3d.com/Manual/SpecialFolders.html
It's a unity feature π
On that makes sense!
Last question: trying to understand https://github.com/needle-tools/needle-engine-modules/blob/main/package/Splines/Splines%7E/SplineWalker.ts#L13
What exactly?
So, this is used to basically get the data from the unity component thatβs not supported out of the box and to have that data passed over to a custom component at https://github.com/needle-tools/needle-engine-modules/blob/main/package/Splines/Splines%7E/SplineContainer.ts#L30
Is that the right way of thinking about that?
I wasnβt sure what those two annotations were
The annotation is just for telling codegen (the one that produces the c# component from typescript) which field type to generate.
This package: https://www.npmjs.com/package/@needle-tools/needle-component-compiler
Actually the syntax changed too (it's now @type My.Namespace.TypeName without the braces)
but should work fine unless you modify the script and it generates the component again
The data is exported from the splines package (the SplineContainer component that comes with the Unity splines package - as you linked above)
The spline walker is just an additional component we used/added for moving some stuff along the spline. You dont have to use that
Got it, but in this context for that you would just remove the donβt generate component part so that you could use it as is
And then itβs just serializing the data from the c# code on one of your gltf extensions to make that data available in ts?
the dont-generate-component is also just for the Unity component generator - so in this case the Unity component already exists (from the Unity splines package) and we dont want to generate another C# component from the typescript file for it
Ahh makes total sense now. I think I get it.
So youβre essentially just pulling data from the C# class by marking the serializable fields and then itβs up to you to create the logic on ts side
Sorry if it's confusing π since we have some annotations that are for the runtime and some that are just for the editor.
Everything that is just a comment //@ .... is in general for the component generator. You can check the readme here for the available commands: https://www.npmjs.com/package/@needle-tools/needle-component-compiler
And the serializer that exports the data from Unity right now does not care about what fields or annotations you have in your Typescript file - later on we might just serialize the fileds that you have actually declared but right now it will all just be exported.
Exactly
We export the data and you or me have to see what we do with it π
Essentially, think of components as just data transfer between both systems. Codegen exists for custom classes to expose to unity
Yes, codegen exists so we dont have to write a C# component for every new Typescript component we want - we just write typescript, codegen comes in and builds the matching C# code for us and we can use it in Unity and assign the stuff
Ok great. This really helps me understand the architecture now. And Iβm assuming from reading the docs that it does this from the custom needle component gltf extension?
The data goes in the needle gltf component extension - but it doesnt care about what data your component contains. We just pack it in there and the runtime engine reads it and builds and attaches the typescript components and tries to deserialize the data to concrete javascript types (e.g. if you have a Vector3 it will be serialized as { x: ... y ... z.... } json and it will deserialize it as e.g. a threejs Vector3 if you add @serializable(Vector3) to it - that's what the typescript decorators are used for
@serializable() is a little bit explained here altough we might need to add more examples to make it clearer: https://github.com/needle-tools/needle-engine-support/blob/main/documentation/scripting.md#serialization--components-in-gltf-files
Ok so itβs just looking at the shape of the json data coming in and seeing what ts object youβre serializing until and tries to make it work based on some simple data transformations checks?
Yes basically π
if you look into @needle-tools/engine/engine/engine_serialization_builtin_serializer.ts you find some implementations of the TypeSerializer - those are responsible for resolving the serialized data
This is great. Thank you for taking some time to chat with me about this.
Of course! π