# Custom Connection Modes

We always want to set `Edit > Editor Preferences > Level Editor > Play > Play Net Mode` to be `Play Standalone`.

### 1. Running PIE server and client locally from Editor. <a href="#connectingclientstodifferentdeploymenttypes-1.runningpieserverandclientlocallyfromeditor" id="connectingclientstodifferentdeploymenttypes-1.runningpieserverandclientlocallyfromeditor"></a>

1. In `Edit > Editor Preferences > General > Morpheus`, ensure that:
   * `EditorConnectionStrategy` is set to `Local`.
2. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `true`.
   * `Run Under One Process` is set to `true`.
3. Then you can hit `Play` with the option `New Editor Window (PIE)` selected.

### 1.1. Testing late joining in PIE

1. When running a PIE server and client, you can enable "late joining" by ticking `Edit > Editor Preferences > General > Experimental > Allow late joining`
2. Once this is ticked, after hitting play, you can add extra clients after the session has already started by clicking the button in the toolbar

   <figure><img src="/files/2rgB3UIKMRK6U4WYxwWP" alt=""><figcaption></figcaption></figure>

### 1.2. Testing disconnection and reconnection <a href="#connectingclientstodifferentdeploymenttypes-2.runningstandaloneserverandclientfromeditorlocally" id="connectingclientstodifferentdeploymenttypes-2.runningstandaloneserverandclientfromeditorlocally"></a>

We have modified the native Unreal `Disconnect` and `Reconnect` console commands to be compatible with the Morpheus Platform:

* `Disconnect` - will cause the local client to disconnect from the server. They will remain in the current world, but will be in the "disconnected" state.
* `Reconnect` - functionally equivalent to the `RestartLevel` console command. The client will attempt to reconnect to the server upon restarting the level.

### 2. Running Standalone server and client from Editor locally. <a href="#connectingclientstodifferentdeploymenttypes-2.runningstandaloneserverandclientfromeditorlocally" id="connectingclientstodifferentdeploymenttypes-2.runningstandaloneserverandclientfromeditorlocally"></a>

1. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Multiplayer Options > Launch Separate Server` is set to `true`.
   * `Multiplayer Options > Run Under One Process` is set to `false`.
   * `Play in Standalone Game > Additional Launch Parameters` contains `-LocalDeployment`.
   * `Server > Additional Server Launch Parameters` contains `-LocalDeployment`.
2. Then you can hit `Play` with the option `Standalone Game`.

Notice that we don't care about the `EditorConnectionStrategy` in this case as it will always be the default value and will be ignored as we are running both the client and the server in other processes outside the Editor.

### 3. Connecting with a PIE Client to a Local External Server that's already running. <a href="#connectingclientstodifferentdeploymenttypes-3.connectingwithapieclienttoalocalexternalserverthatsalr" id="connectingclientstodifferentdeploymenttypes-3.connectingwithapieclienttoalocalexternalserverthatsalr"></a>

1. In `Edit > Editor Preferences > Morpheus Platform > Morpheus`, ensure that `EditorConnectionStrategy` is set to `LocalExternalServer`.
2. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `false`.
3. Then you can hit `Play` with the option `New Editor Window (PIE)`.

Notice that this will only work if the Server was started with the Default Ports (i.e started with `-LocalDeployment`).

### 4. Connecting with a PIE Client to a Cloud Server. <a href="#connectingclientstodifferentdeploymenttypes-4.connectingwithapieclienttoacloudserver" id="connectingclientstodifferentdeploymenttypes-4.connectingwithapieclienttoacloudserver"></a>

1. In `Edit > Editor Preferences > Morpheus Platform > Morpheus`, ensure that `EditorConnectionStrategy` is set to `Cloud`.
2. In `Edit > Editor Preferences > Morpheus Platform > Sign In Settings` ensure that `Per Client Sign In Settings` has a single element of Type `Single Sign On`. If not, add one.
3. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `false`.
4. Ensure that you pass the `-DeploymentName <YourDeploymentName>` argument to the **Editor** when launching it (see `AMorpheusConnection::GetDeploymentName()`):
5. Then you can hit `Play` with the option `New Editor Window (PIE)`.

### 5. Connecting with a Standalone Client to a PIE Server. <a href="#connectingclientstodifferentdeploymenttypes-5.connectingwithastandaloneclienttoapieserver" id="connectingclientstodifferentdeploymenttypes-5.connectingwithastandaloneclienttoapieserver"></a>

1. In `Edit > Editor Preferences > Morpheus Platform > Morpheus`, ensure that:
   * `Editor Connection Strategy` is set to `Local`.
   * `Should Server Use Default Ports` is set to `true`.
2. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `true`.
   * `Run Under One Process` is set to `true`.
3. Then you can hit `Play` with the option `New Editor Window (PIE)`.
4. You could also launch more standalone client with `-LocalDeployment` CLI flag.

### 6. Connecting with a Standalone Client to a Local External Server that's already running. <a href="#connectingclientstodifferentdeploymenttypes-6.connectingwithastandaloneclienttoalocalexternalservert" id="connectingclientstodifferentdeploymenttypes-6.connectingwithastandaloneclienttoalocalexternalservert"></a>

1. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `false`.
   * `Play in Standalone Game > Additional Launch Parameters` contains `-LocalDeployment`.
2. Then you can hit `Play` with the option `Standalone Game`.

Notice that this will only work if the Server is using the default Ports (i.e started with `-LocalDeployment`).

### 7. Connecting with a Standalone Client to a Cloud Server. <a href="#connectingclientstodifferentdeploymenttypes-7.connectingwithastandaloneclienttoacloudserver" id="connectingclientstodifferentdeploymenttypes-7.connectingwithastandaloneclienttoacloudserver"></a>

1. In `Edit > Editor Preferences > Level Editor > Play`, ensure that:
   * `Launch Separate Server` is set to `false`.
   * `Play in Standalone Game > Additional Launch Parameters` contains `-DeploymentName <YourDeploymentName>`.
2. In `Edit > Editor Preferences > Morpheus Platform > Sign In Settings` ensure that `Per Client Sign In Settings` has a single element of Type `Single Sign On`. If not, add one.
3. Then you can hit `Play` with the option `Standalone Game`.

### 8. Running a local deployment without the editor. <a href="#connectingclientstodifferentdeploymenttypes-8.runningalocaldeploymentwithouttheeditor" id="connectingclientstodifferentdeploymenttypes-8.runningalocaldeploymentwithouttheeditor"></a>

1. Ensure that the flag `-LocalDeployment` is passed to both Clients and Server executables which tells them to use the default port numbers instead of random ports.

### Overriding default ports <a href="#connectingclientstodifferentdeploymenttypes-overridingdefaultports" id="connectingclientstodifferentdeploymenttypes-overridingdefaultports"></a>

1. If you want your server to use specific ports, you'd need to pass these CLI args:

* `-morpheusLocalDeploymentRedisPort <YourRedisPort>`.
* `-morpheusLocalDeploymentProxyPort <YourProxyPort>`.

1. If you want your standalone client to use specific ports, you'd need to pass these CLI args:

* `-directRedisPort <ServerRedisPort>`
* `-proxyPort <ServerProxyPort>`

### If your connection is still failing: <a href="#connectingclientstodifferentdeploymenttypes-ifyourconnectionisstillfailing" id="connectingclientstodifferentdeploymenttypes-ifyourconnectionisstillfailing"></a>

* Make sure that the ports being used by the Client are the same ones that the server is using.
  * This can be done by searching through both the Client and Server logs.
* By default, all Clients/Servers started from the editor will be using the default ports unless overridden.


---

# 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://docs.otherside.xyz/platform-documentation/creation/unreal-development/tutorials/reference/connecting-clients-to-different-deployment-types.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.
