Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
423 changes: 423 additions & 0 deletions docs/docs/features/api.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions docs/docs/features/data/helloworld.module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schema: apigear.module/1.0
name: io.world
version: "1.0.0"

interfaces:
- name: Hello
properties:
- { name: last, type: Message }
operations:
- name: say
params:
- { name: msg, type: Message }
- { name: when, type: When }
return:
type: int
signals:
- name: justSaid
params:
- { name: msg, type: Message }
enums:
- name: When
members:
- { name: Now, value: 0 }
- { name: Soon, value: 1 }
- { name: Never, value: 2 }
structs:
- name: Message
fields:
- { name: content, type: string }
177 changes: 177 additions & 0 deletions docs/docs/features/features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
sidebar_position: 2
sidebar_label: "Features"
title: "Unreal Engine Template Features Overview"
description: "Overview of ApiGear Unreal Engine template features: Core API generation, stub implementations, OLink networking, Message Bus IPC, and runtime monitoring."
keywords: [unreal engine features, olink, message bus, stubs, monitor, api generation]
---

import CodeBlock from '@theme/CodeBlock';
import helloWorldModuleComponent from '!!raw-loader!./data/helloworld.module.yaml';

# Features

This guide explains how to use the generated code, what features are available, and their benefits.

:::info
A feature is a part of the template that generates a specific aspect of the code. For example, the `api` feature generates the core API interfaces and the `stubs` feature generates a stub implementation for the API.
:::

## Get started

This template generates Unreal Engine plugins from your API definitions. The generated code integrates seamlessly with both Blueprints and C++.

:::note
Basic Unreal Engine knowledge is recommended. Familiarity with Unreal's plugin system, Blueprints, and C++ module structure will help you get the most out of the generated code.
:::

### Code generation

Follow the documentation for [code generation](/docs/guide/quick-start) in general and [CLI](/docs/cli/generate) or the [Studio](/docs/studio/intro) tools.
Or try first the [quick start guide](../quickstart/index.md) which shows how to prepare an API and generate code from it.

:::tip
For questions regarding the template please go to our [discussions page](https://github.com/orgs/apigear-io/discussions). For feature requests or bug reports please use our [issue tracker](https://github.com/apigear-io/template-unreal/issues).
:::

### Example API

The following code snippet contains the _API_ definition which is used throughout this guide to demonstrate the generated code and its usage.

<details>
<summary>Hello World API (click to expand)</summary>
<CodeBlock language="yaml" showLineNumbers>{helloWorldModuleComponent}</CodeBlock>
</details>

## Features

The template provides features across three layers: **Core** (API and implementations), **Extended** (connectivity and monitoring), and **Infrastructure** (plugin support). These features compose to create a complete plugin architecture:

```mermaid
graph TD
subgraph Application[" Your Application "]
App[Application Code]
end

subgraph API[" API Layer "]
Interface[Interfaces, Structs & Enums]
end

subgraph Implementations[" Implementation Layer "]
Stubs["Stubs<br/>(Local)"]
OLink["OLink<br/>(Network)"]
MsgBus["MsgBus<br/>(IPC)"]
Monitor["Monitor<br/>(Decorator)"]
end

subgraph Infrastructure[" Plugin Infrastructure "]
Plugin["Core & Editor<br/>Modules"]
ApiGear["ApiGear<br/>Framework"]
end

App -->|uses| Interface
Interface -->|implemented by| Stubs
Interface -->|implemented by| OLink
Interface -->|implemented by| MsgBus
Interface -->|implemented by| Monitor
Monitor -.->|wraps| Stubs
Monitor -.->|wraps| OLink
Monitor -.->|wraps| MsgBus
OLink -.->|uses| ApiGear
Monitor -.->|uses| ApiGear
```

*Your application programs against the generated API interfaces. Stubs provide local implementations, OLink and MsgBus connect to remote services, Monitor wraps any implementation for tracing, and the Infrastructure layer provides settings and connection management.*

### Core Features

Core features generate Unreal Engine plugins from your API definition:

- [api](api.md) - generates the core interfaces, data types (structs, enums), and abstract base classes. Provides both Blueprint-compatible interfaces and native C++ access.
- [stubs](stubs.md) - generates ready-to-use implementation stubs as GameInstance Subsystems. Provides a starting point for your business logic and test fixtures for unit testing.

### Extended Features

Extended features add connectivity and monitoring capabilities:

- [olink](olink.md) - provides client and server adapters for the [ObjectLink](/docs/protocols/objectlink/intro) protocol. Use this to connect your Unreal application to remote services or the ApiGear simulation tools.
- [msgbus](msgbus.md) - provides adapters using Unreal's built-in Message Bus for inter-process communication within the Unreal ecosystem.

> **Choosing between OLink and Message Bus?** See the [comparison guide](msgbus.md#when-to-use-message-bus-vs-olink) for a detailed breakdown.

- [monitor](monitor.md) - generates a middleware layer which logs all API events to the [CLI](/docs/cli/intro) or the [Studio](/docs/studio/intro).

### Test Features

- `olink_tests` - test fixtures and specs for OLink client/server functionality.
- `msgbus_tests` - test fixtures and specs for Message Bus adapters.

### Internal Features

These features are generated automatically when required by other features:

- `plugin` - generates the `{Module}Core` and `{Module}Editor` modules:
- **Core module** (`IoWorldCore`): Settings class, implementation factory, and test utilities
- **Editor module** (`IoWorldEditor`): Project Settings UI customization
- `apigear` - core ApiGear plugin with connection management, settings, and editor UI
- `apigear_olink` - OLink protocol support with client/host connections
- `apigear_olinkproto` - ObjectLink protocol library

**Module Settings**: When you enable extended features, the Core module's settings class (`UIoWorldSettings`) gains configuration options accessible in Project Settings:

| Setting | Feature | Purpose |
|---------|---------|---------|
| `TracerServiceIdentifier` | monitor | Select which backend implementation the monitor traces |
| `OLinkConnectionIdentifier` | olink | Select which OLink connection the client uses |
| `MsgBusHeartbeatIntervalMS` | msgbus | Configure heartbeat interval for service discovery |

**Test Utilities**: The Core module includes test helpers for writing your own automation tests:

```cpp
#include "IoWorld/Tests/IoWorldTestsCommon.h"

FIoWorldMessage TestMsg = createTestFIoWorldMessage();
TArray<FIoWorldMessage> TestArray = createTestFIoWorldMessageArray();
```

Each feature can be selected using the solution file or via the command line tool.

:::note
_Features are case sensitive, make sure to always **use lower-case.**_
:::

:::tip
The _meta_ feature `all` enables all specified features of the template. If you want to see the full extent of the generated code, `all` is the easiest solution.
:::

## Folder structure

This graph shows the folder structure generated for a module with all features enabled. Each ApiGear module becomes an Unreal plugin.

```bash
📂ue_project/Plugins
┣ 📂ApiGear
┃ ┣ 📜apigear.uplugin
┃ ┗ 📂Source
┃ ┣ 📂ApiGear
┃ ┣ 📂ApiGearEditor
┃ ┣ 📂ApiGearOLink
┃ ┗ 📂ThirdParty
┃ ┣ 📂nlohmannJsonLibrary
┃ ┗ 📂OLinkProtocolLibrary
┣ 📂IoWorld
┃ ┣ 📜IoWorld.uplugin
┃ ┣ 📂Config
┃ ┗ 📂Source
┃ ┣ 📂IoWorldAPI
┃ ┣ 📂IoWorldCore
┃ ┣ 📂IoWorldEditor
┃ ┣ 📂IoWorldImplementation
┃ ┣ 📂IoWorldMonitor
┃ ┣ 📂IoWorldMsgBus
┃ ┗ 📂IoWorldOLink
```

:::note
The module name `io.world` is converted to PascalCase `IoWorld` for Unreal naming conventions. Each feature generates a separate Unreal module within the plugin.
:::
157 changes: 157 additions & 0 deletions docs/docs/features/monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
---
sidebar_position: 5
sidebar_label: "Monitor"
title: "Monitor Feature: API Tracing and Runtime Debugging for Unreal Engine"
description: "Trace API calls, property changes, and signals at runtime. View live debugging data in ApiGear Studio or CLI for Unreal Engine interfaces."
keywords: [monitor, tracing, debugging, runtime logging, apigear studio, unreal engine]
---

import CodeBlock from '@theme/CodeBlock';
import helloWorldModuleComponent from '!!raw-loader!./data/helloworld.module.yaml';

# Monitor

The `monitor` feature generates tracing capabilities to observe your interfaces at runtime. It enables:

- **Property tracking**: See when properties change and their new values
- **Operation logging**: Track method calls with parameters and return values
- **Signal monitoring**: Observe signal emissions and their data
- **Live debugging**: View all activity in ApiGear Studio or CLI

The monitoring server is integrated into [ApiGear Studio](/docs/studio/intro) and the [CLI](/docs/cli/intro).

For more details on monitoring concepts, see [monitoring documentation](/docs/monitor/intro).

## File overview for module

With our example API definition:

<details>
<summary>Hello World API (click to expand)</summary>
<CodeBlock language="yaml" showLineNumbers>{helloWorldModuleComponent}</CodeBlock>
</details>

The following file structure is generated:

```bash
📂ApiGear/Source/ApiGear
┣ 📂Public
┃ ┗ 📜tracer.h
┗ 📂Private
┗ 📜tracer.cpp

📂IoWorld/Source/IoWorldMonitor
┣ 📂Private
┃ ┗ 📂Generated
┃ ┣ 📜IoWorldMonitor.cpp
┃ ┗ 📂Monitor
┃ ┣ 📜IoWorld.trace.h
┃ ┣ 📜IoWorld.trace.cpp
┃ ┗ 📜IoWorldHelloLoggingDecorator.cpp
┣ 📂Public
┃ ┗ 📂IoWorld
┃ ┣ 📜IoWorldMonitor.h
┃ ┗ 📂Generated/Monitor
┃ ┗ 📜IoWorldHelloLoggingDecorator.h
┗ 📜IoWorldMonitor.Build.cs
```

The `ApiGear` plugin provides the tracer client that connects to the monitoring server. Each module generates interface-specific trace helpers (in the `Monitor` subdirectory) and a logging decorator class that wraps implementations.

## Tracer

The `ApiGear` plugin includes a tracer client that connects to the monitoring server and sends trace data.

### Tracer Configuration

Configure the tracer in your game initialization:

```cpp
#include "tracer.h"

UApiGearTracer* Tracer = GetGameInstance()->GetSubsystem<UApiGearTracer>();

Tracer->Connect(TEXT("ws://localhost:8182/ws"), TEXT("MyUnrealApp"));
```

### Project Settings

You can also configure tracing in Project Settings:

1. Open Project Settings > Plugins > ApiGear
2. Set the Tracer URL (e.g., `ws://localhost:8182/ws`)
3. Set the Application Name for identification
4. Enable/disable auto-connect

## Logging Decorator

The `UIoWorldHelloLoggingDecorator` wraps any `IIoWorldHelloInterface` implementation and logs all interactions to the tracer.

### How it works

The decorator:
1. Wraps an existing interface implementation
2. Intercepts all property access, operation calls, and signal emissions
3. Sends trace data to the connected monitoring server
4. Forwards all calls to the wrapped implementation (transparent)

The decorator extends `UAbstractIoWorldHello` and subscribes to notifications from the wrapped backend service. The key method for setup is:

```cpp
// Set which implementation to wrap and trace
void setBackendService(TScriptInterface<IIoWorldHelloInterface> InService);
```

Once configured, use the decorator exactly like any other implementation—it implements the full interface and forwards all calls to the backend while logging.

:::note
The monitor feature uses generated tracer helper classes (in `Private/`) that handle JSON serialization automatically. The logging decorator manages all tracing - you don't need to interact with these classes directly.
:::

### What Gets Traced

The logging decorator automatically traces:

- **Property writes**: When you call `SetLast()`, a `call` event is sent with the new value
- **Property changes**: When the backend notifies of a change, the full interface state is captured
- **Operations**: All operation calls are traced with their parameters
- **Signals**: Signal emissions are traced with their data

Property reads (`GetLast()`) are not traced since they don't modify state.

## Using the Monitor

### Basic Setup

The logging decorator is a GameInstance Subsystem, so you access it via `GetSubsystem<>()` and configure which implementation it wraps. You can wrap any implementation, including network clients.

```cpp
#include "tracer.h"
#include "IoWorld/Generated/Monitor/IoWorldHelloLoggingDecorator.h"
#include "IoWorld/Implementation/IoWorldHello.h"

UIoWorldHelloImplementation* HelloImpl = GetGameInstance()->GetSubsystem<UIoWorldHelloImplementation>();

UIoWorldHelloLoggingDecorator* TracedHello = GetGameInstance()->GetSubsystem<UIoWorldHelloLoggingDecorator>();
TracedHello->setBackendService(HelloImpl);

TScriptInterface<IIoWorldHelloInterface> Hello = TracedHello;
Hello->Say(Msg, EIoWorldWhen::IWW_Now);
```

### Settings Integration

Instead of manual setup, configure the backend service via Project Settings:

1. Open **Project Settings > Plugins > IoWorld**
2. Set **Tracer Service Identifier** to the backend you want to trace (e.g., `Local` for stubs, `OLink` for network)

The decorator automatically wraps the configured backend during initialization.

## Best Practices

### Performance Considerations

- Tracing adds overhead for serialization and network transmission
- Disable in performance-critical sections if needed
- Consider tracing only specific interfaces of interest
Loading