Class · inherits Model
ProceduralModel
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
Sizeproperty 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 (
SandboxedandCapabilities). - 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
ProceduralModelare replaced with an error state placeholder. The error is stored in theGenerationErrorproperty to give you visibility into why the generation failed.Generator
: ModuleScriptA reference to aModuleScriptthat contains code which defines how theProceduralModelgenerates its contents in response to parameter changes.A reference to a
ModuleScriptcontaining code that defines how theProceduralModelgenerates its contents in response to parameter changes.Setting
Generatortriggers generation using the new generator module. TheAttributestable exported by the module is automatically applied as default attribute values on theProceduralModel.Clearing
Generatorpreserves the current contents of theProceduralModel, and prevents further generation until a new generator is assigned.Guidelines for writing the generator module's
OnGeneratefunction:- Only write results into the provided
targetContainer.OnGenerateshould not modify theDataModeldirectly; writes elsewhere may not interact correctly with engine systems. OnGenerateis allowed to yield and call yielding methods (for example,GeometryServiceCSG APIs). Generation is considered complete wheneverOnGeneratereturns.- 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.
- Only write results into the provided
Size
: Vector3Defines the bounding volume used for generation.The
Sizeof aProceduralModeldefines 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:Sizeis an input that determines how generation occurs, and is explicitly set as a property.The
Sizeproperty represents the physical dimensions of theProceduralModeland is affected byScaleTo. TheOnGeneratefunction in a generator module doesn't need to account for position or scaling: it produces a result of the specifiedSizearound the origin at a scale of 1, and the procedural model system automatically usesPivotTo()andScaleTo()to place and scale the output in theProceduralModel.
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 theProceduralModelis up to date.If nothing is pending, returns
truewithout regenerating. Otherwise runs the generator to completion under a hard timeout, then returnstrueonly if the model is no longer waiting to regenerate and produced noGenerationError. On failure or timeout, returnsfalseand re-queues normal scheduled generation. Unlike scheduled generation, a forced generation doesn't yield to preserve the frame budget, soparameters:Pause()inside the generator returns without pausing.Throws if called from within a generator's
OnGeneratefunction.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
ProceduralModelthat is not in theDataModelbecause generation isn't performed for instances without a parent.This method returns
falseif theProceduralModelis removed from theDataModelwhile 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.