Creator

The creator component is a scripted component that duplicates the entity, its descendants and any components on a specified condition. The creator component is a base class for entity creator components. The interval creator component is a subclass which duplicates the entity, its descendants and any components on a time interval. For further details on all properties associated with this component and how to use this component with scripting, please see the API documentation.

Congestion Zone

The interval creator component will not duplicate an entity until the congestion zone is cleared. If the congestion zone is blocked, the component will wait until the congestion zone is cleared before duplicating the entity.

Properties

The interval creator component properties that are accessible through the inspector.

Interval

The interval of time between which entities are created.

Delay

The initial delay before the first entity is created.

Display

The display method determines how the entity with the creator component should be displayed when the simulation is running. It is one of the following:

  • None - The entity is hidden.
  • Standard - The entity is displayed.
  • Highlighted - The entity is displayed and highlighted.

Geometry

The geometry for the congestion zone. It is one of the following:

  • None - No geometry, disabling the congestion zone.
  • Bounding Sphere - A bounding sphere around the entity and its descendants.
  • Bounding Box - A bounding box around the entity and its descendants.

Layer

The collision layer for the congestion zone. Entities with layers that are set to collide with the specified layer will block the congestion zone.

Kinematics

Whether entities with kinematic rigid bodies should be detected by the congestion zone.

Scripting

The script shown below is an example implementation of a custom creator component, where the period of time T between which entities are created is modelled as a gaussian random variable T ~ N(mean, variance). The sequence of random numbers generated by nextGaussian() is deterministically pseudo-random. In other words, it produces the same sequence of random numbers every time the simulation is run.

import { type Entity, CreatorComponent, Random, Icon, Units, UnitType, Readonly } from "prototwin";

@Icon("mingcute:random-line")
export class RandomCreator extends CreatorComponent {
    @Readonly(true)
    @Units(UnitType.Time)
    time: number;
    @Units(UnitType.Time)
    mean: number;
    variance: number;

    constructor(entity: Entity) {
        super(entity);
        this.time = 0;
        this.mean = 1;
        this.variance = 0;
    }

    public override update(dt: number): void {
        while (this.time <= 0) {
            this.create(); // Create a copy of the entity.
            this.time = Math.max(0, Random.global.nextGaussian(this.mean, Math.sqrt(this.variance)));
        }
        this.time -= dt;
    }
}

The script extends the CreatorComponent base class and calls the create() method to duplicate the entity.