Attachments

Static mesh attachments can be socketed to player characters, for example weapons, glow sticks, or other accessories.

This page describes the process for attaching Unreal StaticMesh assets. You can also use attachments defined in MML - for details see MML Attachments.

Adding attachments to characters

Use the AddAttachment and RemoveAttachment functions on the Morpheus Actor's M2M_CharacterAssetComponent to add and remove attachments. The attachment will then automatically be applied to the character, whether it's in the crowd or a full actor, and regardless of the avatar type (MML or a static mesh).

Note that attachments are NOT REPLICATED. Automatic replication of all possible attachment states would add significant overhead, and would be unnecessary in most projects. Therefore it is up to projects to replicate their own state. This may be as simple as a single background integer specifying which item is equipped - in the OnRep, simply call RemoveAttachment with the previously equipped item and AddAttachment with the new one.

The Add and Remove functions have a Reload Character option. If you're making multiple calls to add and/or remove attachments to a character, it's more efficient to only reload the character on the final call. The character visuals won't be updated until it's reloaded.

The crowd system is limited to 16 total meshes per character including attachments, however up to 32 attachments will work for full actor (non-crowd) players.

Adding an attachment to a character returns a FM2_StaticMeshAttachmentHandle which can be cached to later retrieve this attachment, or the attached Mesh. Note that passing in a null mesh, or a mesh which has already been attached, will return an invalid handle, so be careful not to overwrite any previously saved handle.

Example of using an FM2_StaticMeshAttachmentHandle to retrieve an attached mesh

Customising colors

It is possible to dynamically set material colors for attachments, but it requires some additional setup.

Crowd pipeline setup

Materials are customised by passing in additional color data with each mesh in the crowd. This additional data has a small memory and performance cost to the crowd rendering, so is disabled by default. To enabled it, on the MorpheusActorRenderTargetComponent on your player Morpheus Actor blueprint, look for the Crowd Data property (under Advanced -> Crowd Details).

Either edit the data asset, or create a new data asset of type SkeletalAnimatedCrowdData and set it as the Crowd Data. In the data asset, set NumCustomDataFloatsPerMesh to 4 to enable the color to be passed correctly:

Setting the attachment color

A custom color can be passed into AddAttachment as part of the M2_StaticMeshAttachment struct, or the color can be updated on an existing attachment with M2M_CharacterAssetComponent::SetCustomColorForAttachment. As with adding/removing attachments, these changes will not be visible until the character has been reloaded and the changes are not replicated automatically.

Example of how one might update the colour of an attachment

Material setup

To access the custom color in the mesh material you must use a specific custom node setup.

The material must have the MF_SkeletalCrowdPerMeshCustomDataRGB node followed by a VertexInterpolator node. This node handles reading the crowd data if it's in the crowd, or the standard custom parameter if it's an actor. The material must also have a Vector Param named CustomValue, which will receive the data.

A typical setup should look like this:

The Index input allows you to swizzle the custom data input channels. Typically this should be left as 0, 1, 2 which will pass the color through unchanged.

Last updated

Was this helpful?