Skip to content

Class · inherits Model

ProceduralModel

Official docs ↗

Procedural models support edit-time procedural generation. Instead of manually constructing model content, a procedural model generates its contents automatically in response to parameter changes.

About ProceduralModel

ProceduralModel inherits from Model and supports edit-time procedural generation of its contents. Instead of manually constructing model content, a procedural model generates its contents automatically in response to parameter changes.

Generation is defined by a generator module, a ModuleScript referenced by the Generator property. The engine invokes the module's OnGenerate function to produce the model's contents.

A procedural model regenerates when any of the following inputs change:

  • The Size property of the procedural model, which defines a bounding box for the model to generate within.
  • Any attributes on the procedural mode, as defined by the generator module.
  • The generator's module sandboxing configuration (Sandboxed and Capabilities).
  • The source code of the generator module.

When any of these inputs change, the engine schedules regeneration. This scheduled regeneration is performed by calling OnGenerate and applying its results once it returns. In most cases, generation happens within the same frame, but can be deferred to maintain performance.

Properties 3

  • GenerationError: stringReadOnlyNotReplicatedStores errors that the generator module might encounter during generation.

    If the generator module encounters an error during generation, the contents of the ProceduralModel are replaced with an error state placeholder. The error is stored in the GenerationError property to give you visibility into why the generation failed.

  • Generator: ModuleScriptA reference to a ModuleScript that contains code which defines how the ProceduralModel generates its contents in response to parameter changes.

    A reference to a ModuleScript containing code that defines how the ProceduralModel generates its contents in response to parameter changes.

    Setting Generator triggers generation using the new generator module. The Attributes table exported by the module is automatically applied as default attribute values on the ProceduralModel.

    Clearing Generator preserves the current contents of the ProceduralModel, and prevents further generation until a new generator is assigned.

    Guidelines for writing the generator module's OnGenerate function:

    • Only write results into the provided targetContainer. OnGenerate should not modify the DataModel directly; writes elsewhere may not interact correctly with engine systems.
    • OnGenerate is allowed to yield and call yielding methods (for example, GeometryService CSG APIs). Generation is considered complete whenever OnGenerate returns.
    • Calling parameters:Pause() inside long-running loops lets the engine break up work. It only yields when needed to avoid dropping frames, so calls are low-cost when the frame budget is not exceeded.
  • Size: Vector3Defines the bounding volume used for generation.

    The Size of a ProceduralModel defines the bounding volume used for generation.

    In a standard model, size is a derived output value based on its contents and can be queried using GetBoundingBox(). A procedural model inverts this relationship: Size is an input that determines how generation occurs, and is explicitly set as a property.

    The Size property represents the physical dimensions of the ProceduralModel and is affected by ScaleTo. The OnGenerate function in a generator module doesn't need to account for position or scaling: it produces a result of the specified Size around the origin at a scale of 1, and the procedural model system automatically uses PivotTo() and ScaleTo() to place and scale the output in the ProceduralModel.

Methods 2

  • ForceGeneration() → booleanImmediately runs any pending generation instead of waiting for the scheduled regeneration.

    Generation is normally scheduled soon after a parameter changes so work can be deferred for performance. ForceGeneration() instead runs any pending generation synchronously and returns whether the ProceduralModel is up to date.

    If nothing is pending, returns true without regenerating. Otherwise runs the generator to completion under a hard timeout, then returns true only if the model is no longer waiting to regenerate and produced no GenerationError. On failure or timeout, returns false and re-queues normal scheduled generation. Unlike scheduled generation, a forced generation doesn't yield to preserve the frame budget, so parameters:Pause() inside the generator returns without pausing.

    Throws if called from within a generator's OnGenerate function.

  • WaitForGenerationAsync() → booleanYieldsWaits for generation to complete after making parameter changes.

    Generation is scheduled to run as soon as possible after a parameter changes, but not immediately. Use WaitForGenerationAsync() to wait for generation to complete before parameters are changed.

    This method errors if called on a ProceduralModel that is not in the DataModel because generation isn't performed for instances without a parent.

    This method returns false if the ProceduralModel is removed from the DataModel while generation is in progress, since this cancels the operation.

ProceduralModel also has every member of Model. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.