Roblox UtilitiesDevlHub Roblox Documentation

Class

ProceduralModel

Inherits
Model › PVInstance › Instance › Object
Memory category
BaseParts

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.

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#

GenerationErrorstringStores errors that the generator module might encounter during generation.ReadSafeReadOnlyNotReplicated
GeneratorModuleScriptA reference to a ModuleScript that contains code which defines how the ProceduralModel generates its contents in response to parameter changes.ReadSafe
SizeVector3Defines the bounding volume used for generation.ReadSafe

GenerationError: string#

ReadOnlyNotReplicatedReadSafe

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: ModuleScript#

ReadSafe

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: Vector3#

ReadSafe

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#

ForceGenerationImmediately runs any pending generation instead of waiting for the scheduled regeneration.
WaitForGenerationAsyncWaits for generation to complete after making parameter changes.Yields

ForceGeneration(): boolean#

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.

Returns
  • boolean — Whether the ProceduralModel is up to date after the call: true if generation completed successfully or nothing needed to be regenerated, false otherwise.

WaitForGenerationAsync(): boolean#

Yields

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.

Returns
  • boolean — Was the generation successful?

Inherited members#

Inherited from Model 26
Inherited from PVInstance 4
Properties (2)

Origin, Pivot Offset

Methods (2)

GetPivot, PivotTo

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed