# MML

M² supports loading interactive interoperable MML objects (see [mml.io](https://mml.io/)).

### Compatibility

Each element's compatibility with the rendering engines used by different components of the M² Platform (Unreal and Web) are listed on [mml.io](https://mml.io/). For example: here's the [compatibility table](https://mml.io/docs/reference/elements/m-model#compatibility) for the \<m-model> element.

In cases where an mml element contains a media format, [\<m-video>](https://mml.io/docs/reference/elements/m-video) for instance, we only support formats that are supported by the underlying rendering engine.

### MML Avatars

We use MML for Avatar Models. These can [come from NFTs](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/supporting-an-nft-avatar-collection) or be hand-written and uploaded by a user.

#### Avatar Format

For an MML file to be a valid avatar it must have a single top-level `<m-character>` element specifying the source mesh file. It can also optionally contain `<m-model>` child elements, which you can use to build avatars out of multiple meshes. The skeletons on these meshes must all match the UE5 skeleton. You can also add static meshes as attachments by using the `socket` attribute.

See here for full details and examples: <https://mml.io/docs/reference/elements/m-character>

As an example, a single mesh avatar MML is as simple as this:

```
<m-character src="https://public.mml.io/character-body.glb"></m-character>
```

Whereas an avatar with multiple meshes and an attachment might look like this:

```
<m-character src="https://public.mml.io/character-body.glb"
  <m-model src="https://public.mml.io/character-head.glb"></m-model>
  <m-model src="https://public.mml.io/duck.glb" socket="hand_r" rx="180" ry="10" rz="-90" x="-0.15" y="-0.047" z="0.04" sx="0.1" sy="0.1" sz="0.1"></m-model>
</m-character>
```

To easily make your own compatible GLB mesh files that you can use as part of a valid Avatar MML file, see [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).

Animations don't need to be specified for MML avatars, and will be ignored in the game client. The avatar will be animated using the standard animations for the project (hence the need for meshes to use the correct skeleton).

#### Using MML Avatars in game

No additional setup is needed to enable MML avatars in the game client. Project blueprints can call `M2M_CharacterAssetComponent::LoadCharacterFromUrl` with the URL of an MML avatar and it will attempt to load it for your player character, and replicate it so it's visible to other players. See `WBP_SettingAvatarExample` for an example of enabling users to paste an avatar URL into the settings menu.

Players can also have an MML avatar stored on their profile. By default these won't be loaded in, but you can retrieve the URL with `M2_PlayerProfileSubsystem::GetPlayerAvatarUrl` and load the character as above.

### How to add an MML object to your level

This is a blueprint that spawns an MML object.

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

This is a slightly more involved example of a blueprint. It's a clickable mesh that spawns an MML object on click.

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

### How to delete an MML object from your level

This is a blueprint that sets a reference to a spawned MML document so that you can then use the reference later to remove the document from the world.

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