# Creating a new character

This page outlines the steps involved in setting up your character in a way that is compatible with the Morpheus Platform. Note that there are some steps here that are different to native Unreal, so it is worth even experienced Unreal users looking through this page.

## Setting up your Morpheus Actor

The `Morpheus Actor` is the class that will be responsible for networking your character. For more details on this, see [networking](https://docs.msquared.io/creation/unreal-development/getting-started/networking/networking "mention").

If you are using the [using-the-template-project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project "mention"), `BPM_Example_PlayerCharacter` has been made for you.

{% hint style="info" %}
We require that the Morpheus actor for your main character extends from `M2M_CharacterBase` at the minimum. This is a child of `MorpheusPawnActor` (a specialized form of `MorpheusActor`), that includes implementation of some of our core functionality, such as [crowd-animation](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/the-animated-crowd/crowd-animation "mention"), and [avatars](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars "mention"). For other Morpheus actors in-game, you can go directly from `MorpheusActor` or below.

<img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-bb74a10a4fb4eeabe0d8f84b65866c88363b4bfd%2Fimage.png?alt=media" alt="" data-size="original">
{% endhint %}

Your Morpheus Actor is responsible for spawning its "render target" (the avatar model) and tracking any replicated state. For how these are done, see the following steps:

* [#configuring-your-render-target](#configuring-your-render-target "mention")
* [#updating-your-character-avatar](#updating-your-character-avatar "mention")

## Configuring your Render Target

### What is a Render Target?

Your render target is the "physical representation" of your character. We have different "render targets", at different rendering "LOD Levels". For most casts, LOD 0 is the `Actor` that is used when the player is nearby, and LOD 1 is the "crowd" (see [the-animated-crowd](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/the-animated-crowd "mention")) used for distant actors.

More details on these "Render Targets" in [morpheus-render-targets](https://docs.msquared.io/creation/unreal-development/getting-started/networking/morpheus-render-targets "mention")

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-d6d8d25060dc084e916ff2c507a49267c8a56d03%2Fimage.png?alt=media" alt=""><figcaption><p>A demonstration of the difference between render targets. In this example, there are 3 characters in the world (so 3 <code>BPM_M2Example_PlayerCharacter</code>s), but only 2 render target actors (<code>BP_M2Example_PlayerCharacter</code>). This because we have set the "NumInLOD0" to 1, meaning that other than yourself, only one other character will be a render target actor, and any past that point will be represented in the crowd.</p></figcaption></figure>

### The Pawn Class

Like in traditional Unreal projects, we use the `Pawn` class to represent most players. As mentioned above, the main difference is that for remote characters, we switch between these Render Target Actors, and a "crowd" representation.

We use the pawn class for handling game logic that requires a physical in-game body, e.g. collision or moving the actor through the game world (any networked state needs to be sent through the Morpheus Actor).

If you are using the [using-the-template-project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project "mention"), `BP_Example_PlayerCharacter` has been made for you.

{% hint style="info" %}
We require your main character to extend from `M2_CharacterBase` at the minimum (a child of `Character`). This is to handle some of our core functionality, such as [actor-pooling](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/actor-pooling "mention")and handling custom avatars' [capsules](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/capsules "mention"). If you are using making other Morpheus Actor render targets, you can go directly from `Actor` or below.
{% endhint %}

{% hint style="warning" %}
**Some important things to note regarding using pawns on the Morpheus Platform**

* We do not advise modifying your `SkeletalMeshAsset` to set your character's visuals. Instead, we use an interoperable avatar system (See [avatars](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars "mention")). To configure your character's model, see [#updating-your-character-avatar](#updating-your-character-avatar "mention")
* The `Anim Class` can be modified, but has some caveats:
  * Animations require some specialized techniques to be compliant with the Animated Crowd. See [crowd-animation](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/the-animated-crowd/crowd-animation "mention")
  * Our custom avatar setup requires a specific skeleton to be used (`SKEL_UE5Mannequin`), so this should not be changed if you want to be compatible with our custom avatars.
  * For these reasons, if you do want to change your animations, we recommend duplicating `ABP_M2_Human`, and using it as a starting point.
    {% endhint %}

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

#### Supporting montages

If you want to play montages on the animated crowd, you need to inform the crowd what montages it needs to know about ahead of time, along with the `Anim Class`. To do this, we have a `CrowdAnimationProviderInterface` on our pawn classes, which provides a `GetAnimNameToSequenceMap` function. This is called to inform the crowd of any animations the crowd needs to know about.

If you want to add montages, you can extend/implement this function.

For more details, see [crowd-animation](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/the-animated-crowd/crowd-animation "mention")

### How to define your Render Targets

{% hint style="info" %}
NOTE: The following section applies to release v40 onwards. Prior to that, you will need to configure your render targets via a pawn set. For more details, see [configuring-your-pawn-set](https://docs.msquared.io/creation/unreal-development/getting-started/creating-your-own-character/configuring-your-pawn-set "mention")
{% endhint %}

In your Morpheus Actor, the `MorpheusRenderTargetSettings` are exposed to your `Details` panel:

* If `UseDefaultPawnAsRenderTargetActor` is true, the Morpheus Actor will use the `DefaultPawnClass` in your `GameMode` as the LOD0 actor class
  * If it is false, the `RenderTargetActorClass` will be used. If this is `None`, no render target class will be used.
* If `CrowdEnabled` is true, a crowd will be used for LOD1
  * If `RaycastableCrowdEnabled` is true, then the crowd will support raycasting. For details, see [enabling-raytracing-for-crowd-members](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/enabling-raytracing-for-crowd-members "mention")

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

#### Advanced render target settings

* `CrowdDetails` - this is the details object provided to define how the LOD1 crowd looks:
  * `CrowdData` - this can be left null, but if you want to override any of the default values, you can create your own asset, and provide it here.

    * `Skeleton`: If one is provided, it will change the skeleton used by the crowd. If left null, it will use the one from your LOD0 actor
    * `CrowdAnimInstance`: If one is provided, it will change the `Anim Instance Class` used by the crowd to animate the character. If left null, it will use the one from your LOD0 actor. It doesn't have to match, but generally makes the most sense to match, to ensure animations are consistent.
    * `AnimNameToSequence`: This is a mapping of animation montages that can run on the animated crowd. They can be triggered via e.g. `JM_MontageComponent::PlayMontageByName(MontageName)`. If you want to add montages that you expect to play on the crowd, they will need to be added either here, or on the pawn itself (in their `GetAnimaNameToSequenceMap`). For more details, see [crowd-animation](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/the-animated-crowd/crowd-animation "mention")
    * `NumCustomDataFloats`/`NumCustomDataFloatsPerMesh`: Intended only for specialist use. We advise leaving these unchanged.

    <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-6802ffb213450d3ee17d5faefd6612e23454dc8a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
  * `IsmActorType` - we generally don't advise overriding this. By default (if left as `None`) it uses the `DefaultInstancedMeshActorClass` in `Project Settings -> Morpheus Platform -> Animated Crowd Settings`.
  * `RaycastableCrowdClass` - If left `None`, it will use the `DefaultRaycastableCrowdClass` in the above project settings, if `RaycastableCrowdEnabled` is true. If you want to use a custom raycastable crowd class, you can set it here. For more details, see [enabling-raytracing-for-crowd-members](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/enabling-raytracing-for-crowd-members "mention")
* `ServerRenderTarget` - you can specify a render target to use on the server. Typically this can be left as "No Target", to improve performance on the server, since it doesn't need to deal with actors/crowd members.
* `UseDistinctRenderTargetActorClassForNonAuthClient` - if true, then the non-auth client at LOD0 will use a different render target actor to the auth client (`NonAuthClientRenderTargetActorClass`)
* `LODGroupId` can be set if you want your actor to be in a different group (e.g. rendered in priority over other actors in its group, or handled in a separate group to others). For more details, see [morpheus-render-targets](https://docs.msquared.io/creation/unreal-development/getting-started/networking/morpheus-render-targets "mention")
  * If you don't specify a `LODGroupId`, it will default to the `DefaultLODGroupId` defined in `Project Settings -> Morpheus Platform -> Morpheus LODs`
  * If you specify a `DefaultLODGroup`, it will instead use that, as a custom LOD group, instead of joining the existing group with that Id.

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

## The Player Controller

Player Controllers work basically the same in the Morpheus Platform as they do in native Unreal, on the local client. When your authoritative Render Target Actor is spawned, it will be possessed by your Player Controller.

In the [using-the-template-project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project "mention"), `BP_Example_PlayerController` has been made for you.

## Setting up your Game Mode

### What's in the Game Mode?

The game mode allows use to configure some default classes for your project or map. Important ones to consider here:

* `PlayerMorpheusActorClass`: sets the Morpheus Actor that will be used for your character in the level. If you made your own class in [#setting-up-your-morpheus-actor](#setting-up-your-morpheus-actor "mention"), you will need to make sure it is defined in your active game mode for it to be used.
* `DefaultPawnClass`: sets the pawn class used for player characters. If your Morpheus Actor is configured to `UseDefaultPawnAsRenderTargetActor`, this is what it will use.

{% hint style="info" %}
Remember: If you are on an earlier release than v40, your `DefaultPawnClass` will not be used until you call `ApplyPawnSet`. Your `PlayerMorpheusActorClass` will be created, but it will not have an associated Render Target Actor.
{% endhint %}

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

### How do I set my Game Mode?

The Game Mode used by your project can be configured either by:

* Setting the default game mode via the project settings:

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-7dfd5e2ed682d4ad15acee29e34bcafc8a54d7c3%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
* Overriding the game mode for your specific map, in your `World Settings`:

  <figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-aa4e4955ae3e2bf5ea4c230c920f0be763daa59f%2Fimage.png?alt=media" alt=""><figcaption><p>An example of overriding the default game mode: here to <code>BP_CombatExample_GameMode</code></p></figcaption></figure>

In the [using-the-template-project](https://docs.msquared.io/creation/unreal-development/getting-started/using-the-template-project "mention"), `BP_Example_GameMode` is set as our default game mode, and no override is added to the `ExampleMap` level, meaning that the default will be what is used. It has already been configured to use the `_Example_` classes outlined in the steps above.

## Updating your character avatar

Instead of using regular meshes directly from Unreal, we use an interoperable avatar system, where character models are downloaded via URLs. (See [avatars](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars "mention")). The following is some guidance on how that flow works

### Creating an MML Avatar

We have documentation that outlines the process to go from a 3D model to an MML avatar that can be used in-game, and across Morpheus Platform experiences: [creating-mml-avatars-with-blender-and-free-rigging-tools](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/creating-mml-avatars-with-blender-and-free-rigging-tools "mention")

### Setting your character in-game

Once you have created an MML character URL, or have one you want to use from elsewhere, you can set it via your `CharacterAssetComponent`. For details on how this works, see: [using-an-avatar-in-game](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/using-an-avatar-in-game "mention")

The `BPM_M2Example_PlayerCharacter` has some default behavior that sets some MML avatars for you:

* If a player has a character URL already defined in their profile, that will be used.
* If not, they will default to using a fallback avatar from a pool of example avatars.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-a09416d492a190f2557801a1571ad9c9123c4ee3%2Fimage.png?alt=media" alt=""><figcaption><p>The example logic in <code>BPM_M2Example_PlayerCharacter</code> waits for your profile to be loaded. Once it is loaded, it obtains the profile's <code>Url</code> field, and loads it. The example also includes some fallback behavior, to load some fallback avatars if there is no avatar tied to their profile.</p></figcaption></figure>

* This pool of example avatars is defined via live config (`DefaultAvatar.FormatAvatarUrl`), with the default of `https://casual-filtered-v1.msquaredavatars.com/{0}.mml` - it will select a random URL replacing `{0}` with a number between `DefaultAvatar.MinEntry` and `DefaultAvatar.MaxEntry`.
  * These are some of our publicly available "default avatars" - see [#some-default-characters](https://docs.msquared.io/creation/features-and-tutorials/avatars#some-default-characters "mention")

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