# Reality Function

## Reality Function

`Reality Function` is the base object used to execute reusable gameplay actions.

It is designed to work with the Reality execution system and can be used by:

* Game Phases
* Gameplay event containers
* GameMode logic
* Team-related systems
* Custom execution flows

A function can receive an execution context, which makes it possible to run context-aware logic such as:

* phase-based actions,
* team-based actions,
* custom event execution,
* conditional gameplay flow.

> Use `Reality Function` as the base class for modular gameplay actions that can be reused across multiple systems.

***

## Overview

| Feature              | Description                                                           |
| -------------------- | --------------------------------------------------------------------- |
| Reusable Action      | Represents a gameplay action that can be executed by multiple systems |
| Blueprint Extendable | Can be implemented directly in Blueprint                              |
| Context Aware        | Can receive execution context data                                    |
| Network Execution    | Can run on client, server, or both                                    |
| Modular Design       | Intended for reusable and data-driven gameplay logic                  |

***

## Network Execution Mode

`Reality Function` supports different execution targets.

### Available Values

| Name              | Description                        |
| ----------------- | ---------------------------------- |
| Client            | Executes on the client             |
| Server            | Executes on the server             |
| Client And Server | Executes on both client and server |

***

## Core Execution

### Functions

| Name      | Type             | Description                                                       | Inputs            | Outputs |
| --------- | ---------------- | ----------------------------------------------------------------- | ----------------- | ------- |
| Execute   | Callable / Event | Main action executed by the function                              | Execution Context | —       |
| Is Server | Callable         | Returns whether this execution is currently running on the server | —                 | Boolean |
| Is Client | Callable         | Returns whether this execution is currently running on the client | —                 | Boolean |

***

## Execution Context Support

A `Reality Function` can receive an optional execution context.

### Supported Context Types

| Context                    | Description                                            |
| -------------------------- | ------------------------------------------------------ |
| Reality Execution Context  | Generic execution context                              |
| Reality Game Phase Context | Used when the function runs from a game phase          |
| Reality Team Context       | Used when the function runs from a team-related system |

***

### Common Usage

| Context Type               | Example Usage                       |
| -------------------------- | ----------------------------------- |
| Reality Execution Context  | Generic event execution             |
| Reality Game Phase Context | Run logic based on the active phase |
| Reality Team Context       | Apply logic to a specific team      |

***

## Execution Settings

### Properties

| Name                             | Type    | Description                                                    |
| -------------------------------- | ------- | -------------------------------------------------------------- |
| Can Modify Net Execution Context | Boolean | Allows the function to define its own network execution target |
| Net Execution                    | Enum    | Defines where the function should execute                      |

***

### Behavior

| Rule                                     | Description                                            |
| ---------------------------------------- | ------------------------------------------------------ |
| Can Modify Net Execution Context = true  | The function can define its own network execution mode |
| Can Modify Net Execution Context = false | The network execution mode should not be changed here  |
| Net Execution = Client                   | Executes only on the client                            |
| Net Execution = Server                   | Executes only on the server                            |
| Net Execution = Client And Server        | Executes on both                                       |

***

## Blueprint Workflow

### Common Pattern

| Step | Description                                                             |
| ---- | ----------------------------------------------------------------------- |
| 1    | Create a Blueprint based on Reality Function                            |
| 2    | Implement the Execute event                                             |
| 3    | Read data from the provided Execution Context if needed                 |
| 4    | Configure the Net Execution mode                                        |
| 5    | Add the function to a phase, event container, or other execution system |

***

## Typical Use Cases

| Use Case                                     | Recommended Setup                              |
| -------------------------------------------- | ---------------------------------------------- |
| Run logic when a phase begins                | Add the function to a phase Begin Actions list |
| Run cleanup when a phase ends                | Add the function to a phase End Actions list   |
| Execute a team-specific action               | Use a Team Context                             |
| Execute a phase-specific action              | Use a Game Phase Context                       |
| Run server-authoritative gameplay logic      | Set Net Execution to Server                    |
| Run local UI or feedback logic               | Set Net Execution to Client                    |
| Reuse gameplay logic across multiple systems | Build a reusable Reality Function Blueprint    |

***

## Best Practices

| Recommendation                         | Description                                          |
| -------------------------------------- | ---------------------------------------------------- |
| Keep each function focused             | One function should handle one clear action          |
| Use the correct context type           | Read only the data relevant to the action            |
| Set the right network target           | Avoid running server-only gameplay on the client     |
| Reuse functions across systems         | Functions are designed to be modular                 |
| Use server execution for state changes | Best for score, progression, and authoritative logic |

***

## Notes

| Topic              | Note                                                        |
| ------------------ | ----------------------------------------------------------- |
| Base Action Class  | This is the main base class for executable gameplay actions |
| Blueprint Friendly | Intended to be extended in Blueprint                        |
| Context Driven     | Works best when used with execution contexts                |
| Network Aware      | Supports explicit client/server targeting                   |

***

## Related Pages

| Page                       | Description                                               |
| -------------------------- | --------------------------------------------------------- |
| Reality Context            | Base context system used during execution                 |
| Reality Execution Context  | Generic execution result context                          |
| Reality Game Phase Context | Context used during phase execution                       |
| Reality Team Context       | Context used during team-related execution                |
| Reality Game Phase         | Uses functions in begin and end actions                   |
| Reality Game Data          | Uses gameplay event containers that can execute functions |

***

## Summary

| Item             | Description                                             |
| ---------------- | ------------------------------------------------------- |
| What it is       | Base class for reusable executable gameplay actions     |
| Used by          | Phases, gameplay events, team systems, and custom logic |
| Main entry point | Execute                                                 |
| Context support  | Yes                                                     |
| Network support  | Client, Server, or Client And Server                    |


---

# 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://beyond-sandbox.gitbook.io/realitysdk/documentation/gamemode/reality-function.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.
