# Setup Play-in-Editor

Setting up the common classes

The assets present in Morpheus Platform are read only - in a downstream project, you cannot modify them, only extend from them, or use them as reference. Therefore if you want to modify different classes' behavior, or add extra functionality, you will need to make your own versions of the assets and use them instead. There are different ways of doing this:

### Play settings

Please ensure these settings are configured.]

1. From your editor, select the `Play` drop-down. Then select `Advanced Settings...`

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-e5b4d060dd0bc7c04003698190873b456c59267f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

2. Ensure the following advanced settings are configured
   1. In **Additional Launch Parameters** enter `-LocalDeployment`
   2. Set **Launch Separate Server** to **✔️**
   3. Set **Play Net Mode** to `Play Standalone`
   4. Set **Run Under One Process** to **✔️**

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-e2565b3d522ce11707fc50996ee53883c374d642%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Using the template project

If you create your project using the `M² Base Project`, the majority of commonly overridden assets will be already made for you, e.g. `BPM_Example_PlayerCharacter`. These will be writable, renamable etc. so can act as a starting point for your project.

For further details of this flow, see [Using The Template Project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project).

### Summary

When making a new project using the Morpheus Platform defaults, the following is a list of classes to consider making your own versions of, to extend the Morpheus Platform functionality whilst adding your own:

{% hint style="info" %}
The assets below are what are made automatically for you by [using the template project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project), so the simplest flow would be to start from there.
{% endhint %}

<table><thead><tr><th width="312">Asset to override</th><th width="158">Copy or Inherit?</th><th>Where to apply?</th></tr></thead><tbody><tr><td><code>BP_M2Example_GameMode</code></td><td>Inherit</td><td>Project Settings -> Default GameMode, or World Settings -> GameMode Override</td></tr><tr><td><code>BP_M2Example_PlayerController</code></td><td>Inherit</td><td>In the Game Mode (<code>Player Controller Class</code>)</td></tr><tr><td><code>BPM_M2Example_PlayerCharacter</code></td><td>Inherit</td><td>In the Game Mode (<code>Player Morpheus Actor Class</code>)<br></td></tr><tr><td><code>BP_M2Example_PlayerCharacter</code></td><td>Inherit</td><td>Either via the Game Mode (<code>Default Pawn Class</code>), or via the role's pawn set asset (see the further details)<br></td></tr><tr><td><code>BP_M2Example_HUD</code><br></td><td>Either</td><td>In the Game Mode (<code>HUD Class</code>)</td></tr><tr><td><code>M2M_MorpheusGameState</code></td><td>Inherit</td><td>In the Game Mode blueprint (<code>Morpheus Game State Class</code>)</td></tr><tr><td><code>WBP_M2Example_HUD</code></td><td>Copy</td><td>In your HUD BP</td></tr></tbody></table>

### In more detail:

* The GameMode: This configures a bunch of the classes used in your level, e.g. the player controller and HUD classes outlined below. If you want to make a new game mode, it should extend `BP_M2Example_GameMode`

  * To apply your game mode, you can either modify per-level in your world settings, or modify the default in your project settings -> Maps & Modes.

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-f437965c0c2cc7cd1278e45989c9a31a55c81675%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

#### The Character:

* The PlayerController: Should extend `BP_M2Example_PlayerController`.
* The Morpheus Actor: The representation of a client's character that is used for replication. Should extend `BPM_M2Example_PlayerCharacter`.

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-713ea4190cfbed52f1894f5f190e699e85228108%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
* The Render Target Actor(s): The actual character spawned in-game to represent a player. Should extend `BP_M2Example_PlayerCharacter`
  * If you want to add further customization to the pawns used, e.g. wanting different roles to have different pawns, or want to make changes to the "animated crowd", you can configure them in your roles table's pawn set asset (the `Pawn Lod Level Set` field):
    * For a given role, its `PawnLodLevelSet` controls what render target is used.

      <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-82b228641384eaf93aa24d24ad3a77fb216b83b1%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
    * If you make a new pawn set asset (copying the existing one), you can swap out its `Base Pawn` and LOD0 `Actor Class`

      <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-a219676b4d79dc34731f3db85ba2cd051256618c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
* The UI:
  * The HUD BP: The logic responsible for spawning the HUD, and managing our UI. An example has been made in `BP_M2Example_HUD`, which can be used as an example that can either be copied or extended.
  * The HUD WBP: The actual HUD widget that contains the in-game UI. To use your own HUD widget, we recommend making a copy of `WBP_M2Example_HUD` as a starting point.\
    To use your new HUD, you can change the Game Layer Class in your HUD BP.

{% hint style="info" %}
There are some other base classes in msquared that can be used as valid starting points, such as accessing the C++ directly (via `PlayerController`, `M2_CharacterBase` or `M2M_CharacterBase`). However, these will be missing some of the expected Origin features, so only use these if you really know what you're doing.
{% endhint %}

### Setting up the map

When making a new map, check the world settings, to make sure everything is as expected:

* The GameMode Override: Make sure it points to your new game mode
* The Roles table: You can configure the default role, and the roles table used here

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-dfea4f515171b0de38e2582fbe94a57b2893e54a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
* The Singletons: There are a number of singleton actors that are spawned when the game is started, and enable various bits of Origin functionality. For more details on these, see [singletons](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/singletons "mention").

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-0b711ebe91a247e5a3ebb2ac2e3c1ac69808e0f8%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The MorpheusGameState class: This game state is similar to the unreal native game state, but with the benefit of being replicated by morpheus. Use this instead of unreal's game state

To set it up, go to your GameMode blueprint class and set it in the dropdown

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-b84303eb1ea769a94d25b4c4297b238cdffe8f8d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

To retrieve the morpheus game state, use the GetMorpheusGameState function

### Changing animations

Your characters' animations are controlled in the `ABP_M2_Human`. Making changes to your Animation Blueprint in a downstream project is unfortunately quite an involved process currently compared to native Unreal, due to needing to be applied to both actor render targets and the animated crowd. If you do want to do this, please get in touch!

## Configuring to use MMLs

There are a currently a few workarounds required for full functionality (especially related to MMLs) when using Play-in-Editor functionality.

{% hint style="info" %}
The following sections are current required to place MMLs when in Play-in-Editor mode - this requirement will be removed in a future update.
{% endhint %}

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-df82f99143d0c58106ed928f6e76facf2b1a0f2c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Ensure you're using the correct game mode

You need to be using the `BP_Origin_GameMode` (configurable via world settings), or a game mode that is a child of this.

{% hint style="info" %}
You may need also need to add this change to the template maps: `InfinitySpace` and `Meadow`. A fix for this will be rolled out in a future release.
{% endhint %}

## Configuring Sign-in Settings

{% hint style="info" %}
You can find the current sign-in settings by navigating to `Editor preferences > General > Sign in settings`
{% endhint %}

When you first download the editor and create a new project, your sign-in settings will be configured such that you can immediately start PIE with no other modifications. This section will outline how you can configure your sign-in settings to have more control over how your individual clients and server authenticate.

{% tabs %}
{% tab title="Settings" %}

| Setting name                                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Offline Mode                                | <p>Skips server and client authentication. When enabled you will not have account information and will not be capable of interacting with the Morpheus platform backend.</p><p>This is a good fallback if you experience authentication errors and just need to run PIE to test non-authenticated actions.<br><br>Default value: <em><strong>false</strong></em>.</p>                                                                         |
| Per Client Sign in Settings                 | <p>The sign in method and parameters to be used by the spawned clients. You must have at least as many configured Per Client Sign in Settings as clients you will be launching in PIE.<br><br>Default value: 4 clients configured to sign in with SSO.</p>                                                                                                                                                                                    |
| Trusted Client Api Key                      | <p>The Api key used to authenticate your local trusted clients (e.g., Sentinel and Remote Viewer).<br><br>This is an internal-only feature.</p>                                                                                                                                                                                                                                                                                               |
| Use Local Bot Api Key                       | <p>Determines whether locally spawned bots should authenticate.<br><br>This is an internal-only feature.<br><br>Default value: <em><strong>false</strong></em>.</p>                                                                                                                                                                                                                                                                           |
| Local Bot Api Key                           | <p>The Api key used to authenticate local bots.<br><br>This option is only available when <code>Use Local Bot Api Key</code> is enabled<br><br>This is an internal-only feature.</p>                                                                                                                                                                                                                                                          |
| Use Transient Users for Bots                | <p>Determines whether the authenticated locally spawned bots should be granted a user account.</p><p><br>This option is only available when <code>Use Local Bot Api Key</code> is enabled.<br><br>This is an internal-only <a href="https://www.notion.so/Testing-with-Authenticated-Bots-Transient-Users-1d17560da1e380b4809ef0123160037e">feature</a>.<br><br>Default value: <em><strong>false</strong></em>.</p>                           |
| Transient User Allocation Token             | <p>The allocation token used to request user accounts for the locally spawned bots.<br><br>This option is only available when <code>Use Transient Users for Bots</code> is enabled.<br><br>This is an internal-only <a href="https://www.notion.so/Testing-with-Authenticated-Bots-Transient-Users-1d17560da1e380b4809ef0123160037e">feature</a>.</p>                                                                                         |
| Use Local World for PIE                     | <p>When this is enabled, the user will be granted a local world context which persists between PIE sessions. It is analogous to a deployed world and can be used to test any requests and functionality made with <code>World</code> scope.<br><br>When <code>Server Uses Client Sign in Settings for PIE</code> is disabled, the server will fall back to authenticating with SSO.<br><br>Default value: <em><strong>true</strong></em>.</p> |
| Server Uses Client Sign in Settings for PIE | <p>When enabled, the server will sign in with the sign in method and credentials defined by the first <code>Per Client Sign in Setting</code> .<br><br>Default value: <em><strong>true.</strong></em></p>                                                                                                                                                                                                                                     |
| Client Sign in Stall Method                 | <p><em><strong>Advanced feature</strong></em>.<br><br>Users can create a blueprint inheriting from <code>J\_SignInStallMethodCommon</code> which will allow them to pause bootflow during sign-in until some condition is met.</p>                                                                                                                                                                                                            |

The default settings are shown below

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-6a3cbc41c0d7e2050599f4166958f9924100a9c2%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Below are some common sign-in setups and the setting modifications from the default settings to use them

| Setup                                                                                                                                                                                  | Server/Client Behaviour                                                                                                                                                                                                                                                                                                         | Notes                                                                                                                                                                                                                                                                                                                              |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Default                                                                                                                                                                                | <p>Server and up to 4 clients will use SSO and share credentials.<br><br>If you do not have credentials saved in the credential manager from a previous PIE instance, the server will authenticate first (prompting SSO popup that you must confirm). The credentials will then be saved and the clients will authenticate.</p> |                                                                                                                                                                                                                                                                                                                                    |
| <p>Offline Mode<br><br>- Enable <code>Offline Mode</code></p>                                                                                                                          | Server and Client will both skip authentication.                                                                                                                                                                                                                                                                                | Things may break! As servers and clients in offline mode are not able to perform authenticated actions we don't guarantee all features will work as expected.                                                                                                                                                                      |
| <p>Bearer token<br><br>- Change the <code>Per Client Sign in Settings</code> <code>Type</code> to <code>User Supplied Bearer Token</code><br>- Paste a bearer token into the field</p> | The server and clients will all authenticate with the supplied bearer token. This setup will completely avoid SSO requiring no saved credentials and no prompt window.                                                                                                                                                          | <p>Bearer tokens are only valid for 1h. Once your token expires, requests and logins will fail until you supply a new bearer token.<br><br>Clients and server can share the same bearer token.</p>                                                                                                                                 |
| <p>Api key<br><br>- Disable <code>Use Local World for PIE</code>.<br>- You will need to perform <a href="#set-up-server-credentials">Editor sign-in</a></p>                            | <p>The server will authenticate with Api key.<br><br>Clients will authenticate with the configured <code>Per Client Sign in Settings</code>.</p>                                                                                                                                                                                | <p>Your PIE session will not have a world context to make requests from. This can lead to errors for actions and requests requiring a <code>World</code> scope.<br><br>This was the default server sign-in method prior to local worlds. It can serve as a good fallback if you see sign-in errors related to the local world.</p> |
| {% endtab %}                                                                                                                                                                           |                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                    |
| {% endtabs %}                                                                                                                                                                          |                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                    |

### Local world authentication

By default, PIE sign-in is configured to use local-worlds. This requires no configuration by the user and should work immediately. You can check whether this setting is enabled by navigating to

`Editor preferences > Sign in settings > Use Local World For PIE`.

{% hint style="warning" %}
If you disable this setting, you will need to [Set up server credentials](#set-up-server-credentials).
{% endhint %}

### Set up server credentials

{% hint style="info" %}
This is only relevant if you don't have [local world authentication](#local-world-authentication) enabled.
{% endhint %}

In Editor Preferences, in the `Sign-in settings` section, change your settings to reflect the following where:

* `Offline Mode` is NOT ticked

In the Editor, click on the "Editor Sign In" button on the toolbar

{% hint style="info" %}
The Editor Sign In button will only appear if [Local world authentication](#local-world-authentication) is not enabled
{% endhint %}

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-9dc8f4740945b96b62f83e595bceaf7c0364b869%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

You will be requested to sign in with your Google Account in your main system browser. Once complete, you will be presented with a list of api keys:

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-dfeebaa1085c17b3fbc19b19c34f75513de073f5%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The name will depend on the key your organization admin set up.

Select the key they instructed you to use and click "ok".

### Set up client credentials

In Editor Preferences, in the `Sign-in settings` section, change your settings to reflect the following where:

* `Offline Mode` is NOT ticked
* The `Per Client Sign In Settings` property has the `Single Sign On` element

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-114ad80093e70029a278b7fead17db0d92212688%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
