@serializable and other decorators
The following table contains available Typescript decorators that Needle Engine provides.
You can think of them as Attributes on steroids (if you are familiar with C#) - they can be added to classes, fields or methods in Typescript to provide additional functionality.
Field & Property Decorators
@serializable()
Add to exposed / serialized fields. Is used when loading glTF files that have been exported with components from Unity or Blender.
@syncField()
Add to a field to network the value when it changes. You can pass in a method to be called when the field changes
@validate()
Add to receive callbacks in the component event method onValidate
whenever the value changes. This behaves similar to Unity's onValidate.
Method Decorators
@prefix(<type>)
(experimental)
Class Decorators
@registerType
No argument. Can be added to a custom component class to be registered to the Needle Engine types and to enable hot reloading support.
Examples
Serializable
SyncField
The @syncField
decorator can be used to automatically network properties of your components for all users (visitors of your website) connected to the same networking room. It can optionally take a callback function that will be invoked whenever the value changes.
To notify the system that a reference value (like an object or an array) has changed you need to re-assign the field. E.g. like this:
myField = myField
The callback function can not be an arrow function (e.g.
MyScript.prototype.onNumberChanged
works foronNumberChanged() { ... }
but it does not formyNumberChanged = () => { ... }
)
Validate
Prefix
Last updated