Model Objects
Overview
Model objects in MetaForge represent the core data structures that are used for creating custom editor windows and handling various game data configurations. By defining model objects, developers can easily create and manage metadata-driven properties that are editable within the Unreal Engine editor.
Model objects are defined as subclasses of UObject and are customized to contain specific properties that you want to expose and modify within the editor. These objects are essential for integrating MetaForge into your game development workflow.
Defining a Model Object
To define a model object, follow these steps:
Create a new C++ class that inherits from
UObjectand implements theIDataModelinterface.Add metadata-driven properties to the class, which will be exposed and editable within the Unreal Engine editor.
Use Unreal's UPROPERTY system to mark properties for editing and serialization.
Example Code
Here is an example of defining 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:
virtual FName GetModelId() override {
return IdProperty;
}
UPROPERTY(EditAnywhere, Category = "MyModel", meta = (Component = "SNameProperty"))
FName IdProperty;
UPROPERTY(EditAnywhere, Category = "MyModel", meta = (Component = "SFloatProperty"))
float ValueProperty;
};In this example:
UMyModelObjectis the model object that inherits fromUObjectandIDataModel.IdPropertyis an identifier for the model, exposed to the editor.ValuePropertyis another editable property, allowing users to modify its value in the editor.
Metadata Annotations
Metadata annotations are used to customize how properties are displayed and edited within the editor. In the above example, meta = (Component = "SNameProperty") specifies that the IdProperty should use a particular editor component for visualization and editing.
Common metadata annotations include:
Component: Specifies the editor component used for visualization (e.g.,SNameProperty,SFloatProperty).If: Specifies a condition for displaying the property (e.g.,If = "Condition").Validator: Specifies a function to validate the property's value (e.g.,Validator = "UFUNCTION_NAME").
Best Practices for Model Objects
Keep It Simple: Only include properties that need to be exposed and modified within the editor. Avoid overcomplicating model objects with unnecessary logic.
Use Meaningful Categories: Use the
Categoryspecifier to group related properties logically, making it easier for users to navigate within the editor.Leverage Metadata Annotations: Use metadata annotations to enhance the user experience when interacting with model objects in the editor.
Summary
Model objects are the foundation for creating configurable data structures in MetaForge. By defining model objects and applying appropriate metadata annotations, developers can create intuitive editor interfaces to manage game data efficiently.
Last updated