# References

## Overview

References in MetaForge provide a way to establish relationships between different model objects. By using references, developers can link data together, making it easier to create interconnected models and implement complex game data structures in the Unreal Engine editor. References allow you to point from one model object to another, providing a flexible and reusable approach to managing game assets.

<figure><img src="/files/tKluvBdABLJLsa9nBkHa" alt=""><figcaption><p>Reference field showing selectable options of another model type</p></figcaption></figure>

## Defining References

References in MetaForge work by defining a property to hold the ID of the referenced model. You can use the `UPROPERTY` macro to define the reference, specifying the metadata to configure how the reference works.

### Example Code

Here is an example of defining a reference in a model object:

```cpp
#pragma once

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

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

public:
    UPROPERTY(EditAnywhere, meta = (Component="SReferenceProperty", LoadFunction="GetReferences"), Category = "Stat")
    FName* MyOtherObjectReference;

    UFUNCTION()
    TArray<MyOtherObject*> GetReferences() const;
};
```

In this example:

* **`MyOtherObjectReference`** holds the ID of the referenced model.&#x20;
* **`LoadFunction`** is a `UFUNCTION()` defined on the model object that returns a `TArray` of `IDataModel`-derived object pointers.
* References only work for objects that are derived from `UObject` and `IDataModel`.

## Summary

References are a powerful feature in MetaForge that allow you to create relationships between model objects. By using references, you can build complex and interconnected data structures while maintaining flexibility and reusability. Whether you need strong or weak references, MetaForge provides the tools to manage these relationships effectively within the Unreal Engine editor.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rockon-games.gitbook.io/metaforge-documentation/readme/references.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
