MetaForge Documentation
Fab Store PageDiscord
  • MetaForge
    • Getting Started
    • Plugin Configuration
    • Runtime Configuration
    • Project Configuration
    • Model Objects
    • Model Managers
    • Registering Models
    • Conditionals
    • Validators
    • References
    • References (Advanced)
    • Property Drawers
    • List Properties
    • IDE File Templates
    • Runtime Usage
  • Contact Us
Powered by GitBook
On this page
  • Overview
  • Defining Conditionals
  • Example Code
  • Use Cases for Conditionals
  • Best Practices for Conditionals
  • Summary
  1. MetaForge

Conditionals

Overview

Conditionals in MetaForge are used to control the visibility and editing capabilities of model object properties within the Unreal Engine editor. By using conditionals, developers can create dynamic and context-sensitive editor interfaces, ensuring that only the relevant properties are displayed or modified based on specific conditions.

Defining Conditionals

To use conditionals, you can annotate your model object properties using the If metadata tag. This tag allows you to specify a condition, which is a Python expression evaluated against the properties of your object to determine whether a given property should be displayed in the editor.

The Python expression uses Python naming conventions, which can be a bit tricky at first. For example, Unreal-style property names like bEnableAdvancedSettings must be written in snake_case (b_enable_advanced_settings) in the Python condition.

It's important to convert Unreal's CamelCase or PascalCase property names to snake_case when writing conditions. Additionally, any properties used in conditionals must be marked as BlueprintReadWrite to ensure they can be accessed and evaluated properly in the editor.

Example Code

Here is an example of using conditionals in a model object:

#pragma once

#include "CoreMinimal.h"
#include "UDataModel.h"
#include "UMyModelObject.generated.h"

UCLASS()
class UMyModelObject : public UObject, public IDataModel
{
    GENERATED_BODY()

public:
    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "MyModel", meta = (Component = "SBoolProperty"))
    bool bEnableAdvancedSettings;

    UPROPERTY(EditAnywhere, Category = "MyModel", meta = (If = "b_enable_advanced_settings", Component = "SFloatProperty"))
    float AdvancedSettingValue;
};

In this example:

  • bEnableAdvancedSettings is a property that acts as part of the condition for displaying AdvancedSettingValue. It must be marked as BlueprintReadWrite to be used in a conditional.

  • AdvancedSettingValue is only displayed in the editor if the condition bEnableAdvancedSettings evaluates to true.

Use Cases for Conditionals

  • Advanced Settings: Show or hide advanced configuration options based on a simple checkbox or toggle.

  • Contextual Properties: Display properties only when certain conditions are met, such as the type of an object or the value of another property.

  • Simplified Editor Interface: Reduce clutter in the editor by hiding irrelevant properties until they are needed.

Best Practices for Conditionals

  • Use Clear Conditions: Ensure that the conditions used for hiding or showing properties are easily understandable and predictable for the user.

  • Avoid Overuse: Too many conditionals can make the editor interface confusing. Use them judiciously to improve the user experience.

Summary

Conditionals provide a powerful way to create context-sensitive and dynamic editor interfaces in MetaForge. By using conditionals, you can enhance the usability of your tools by showing only relevant information to the user, reducing clutter and making the editor experience more intuitive.

PreviousRegistering ModelsNextValidators

Last updated 5 months ago