Components

This section documents available components, which provide various functionalities to objects in the project. Components can be attached to a scene node to add behavior to it.

To add any component, use add_component function:

add_component(node, new Camera()) // add 3D camera to a scene with default values

You can also create your own components by inheriting from the Component class and overriding its methods, for example:

class RotateMeComponent : Component
    angle : float = 0.
    speed : float = 1.

    def override on_initialize() : void {
        // will be called when the component appears on the scene (attached)
    }

    def override on_update() : void {
        // will be called each frame
        angle += get_delta_time() * speed
        rotate_object(nodeId, dashChildRotVec, angle)
    }

    def override on_destroy() : void {
        // will be called when the component is destroyed.
    }

add_component(node, new RotateMeComponent(speed = 0.5)) // add custom component to a scene

Sometimes you may want to add requirements to ensure that a component can only be added to a node if it has certain other components attached to it. This can be done by using the require annotation:

[require(component=(RequiredComp1, RequiredComp2))]
class MyComp : Component {
    // ...
}

Fields export

Exporting a structure field controls its serializing behavior. An exported field is both editable in node inspector and saved in prefab files.

By default, all public fields are exported, while private are not. This behavior can be changed with annotations (see below). Const fields are never exported.

Fields annotations

To modify field behavior in serializer or editor, you can add annotations to it. Annotations are added by placing them before the field declaration, any number of non-conflicting annotations can be added to one field. Annotations can be added to a field of any structure, not just to descendants of Component class, but custom components are their main use case.

Currently supported annotations:

  • @export: explicitly export the field

  • @no_export: explicitly don’t export the field. Same as @export=false

  • @view_name: rename the field for the editor. Can be any sequence of characters.

  • @serialize_name: rename the field for serialization. Use case: you want to rename a field that is already saved in a prefab. By placing its old name in @serialize_name, you can maintain compatibility with old prefabs, as this is the name that serializer will use. Can only be a valid daslang name.

  • @hint: tooltip for the field in the editor.

  • @color: use a color picker for this field in the editor. Applicable only to float4 (RGBA) and float3 (RGB) fields, as well as containers with values of such types.

  • @collapse: make the string input box collapsible, and allow it to have any number of lines (instead of default 5). Applicable only to string fields.

Annotations showcase:

class AnnotationsComponent : Component {
    @export private export_me : int
    @no_export do_not_export_me : float

    @view_name="Hello, world!"
    @serialize_name=hello_world // string without space do not require quotes
    bye_world : string

    @hint="This is a color field"
    @color
    color : float4
}

Built-in components

Here are the components currently added:

  • Camera: allows an object to render a 3D camera

  • Mesh: renders a 3D mesh

  • LODSelector: allows to reduce the number of polygons based on distance from the camera

  • AmbientSettings: affects the global ambient lighting

  • ShadowSettings: controls the settings for shadows in a scene

  • Tonemap: controls the global color grading of the scene

  • Sky: renders a skybox

  • AntiAliasing: controls the anti-aliasing settings of a scene

  • SpotLight: represents a spotlight source of light

  • PointLight: represents a point light source of light

  • DirectionLight: represents a directional light source of light

  • Audio: controls audio playback for an object

  • RigidBody: enables physics simulation for an object

  • SpringJoint: defines a spring joint between two objects

  • HingeJoint: defines a hinge joint between two objects (like a door)

  • SixDofJoint: defines a six-degrees-of-freedom joint between two objects (most configurable joint)

  • Collider: defines a generic collider with a single or more shapes for an object

  • CollisionListener: custom handlers for collision callbacks

  • CharacterController: allows the character-like movement

  • Animator: base component for playing animations which holds internal animation state

  • SingleAnimationPlayer: helper component for playing a single animation

  • UICanvas: defines a UI canvas

  • Text: renders 2D text

  • Text3D: renders 3D text

  • UIImage: renders an image in a UI canvas

  • UIHorizontalLayout: arranges child UI nodes horizontally

  • UIVerticalLayout: arranges child UI nodes vertically

  • UIFlowLayout: arranges child UI nodes sequentially wrapping them to the next row if they don’t fit horizontally