SpeedTree
    Show / Hide Table of Contents

    Anatomy of a Rule

    Learn about the base requirements to structure a Rule script.

    Note

    To compose a Rule script, you must use the Lua scripting language.

    Minimum functional Rule structure

    To compose a basic functional Rule, you minimally have to specify two complementary statements, each represented by a code line:

    1. A statement that defines the Rule, which includes the definition of a user control.
    2. A statement that sets the model property value you want to manipulate with the user control.

    The first statement outputs a variable value that the second one uses as an input. You can additionally process the variable value in between, if needed.

    Rule definition

    Here's the generic syntax of a statement that defines a Rule and its user control.

    <variable_name> = <rule_definition_function>(<rule_name>, <reference_values>)
    
    Key element Description
    <variable_name> The name of the variable that holds the value controlled by the Rule.
    <rule_definition_function> The function that defines which type of control to use in the UI (slider, checkbox...) Several rule definition functions are available.
    <rule_name> The name of the Rule, and optionally the name of its grouping category, in the UI.
    <reference_values> Static values that frame the Rule according to its type, including default values.

    Property value setup

    Here's the generic syntax of a statement that sets a model property value to manipulate.

    <property_value_setup_function>(<target_property_identifiers>, <input_parameters>)
    
    Key element Description
    <property_value_setup_function> Function to specify which type of property setup to perform. Several property value setup functions are available.
    <target_property_identifiers> Parameters to specify which property of which object to control with the Rule.
    <input_parameters> Parameters to set the property value according to the variable <variable_name> controlled by the Rule.

    Additional resources

    • Introduction to Rules
    • Create a slider Rule
    • Rule script helpers in the Property bar
    • Rules window reference
    • SpeedTree functions usable in Rules
    • Lua scripting reference documentation
    Copyright © 2023 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX.