Avatar Physics Assets
Assigning and replicating physics assets used on characters with an MML avatar.
Last updated
Was this helpful?
Assigning and replicating physics assets used on characters with an MML avatar.
Last updated
Was this helpful?
The Morpheus Platform primarily uses MML avatars for its characters, which allows players to bring in their own custom avatar. The mesh data for this avatar is streamed in to every observing client for rendering, but this does not include physics data, which means that each player will not see a physics asset on any remote player's character.
The Avatar Physics Asset component allows you to configure which physics asset should be assigned to remote characters based on their avatar. You can assign a global physics asset to be used for all characters, configure your game to only use capsule components, or assign different physics assets depending on the shape of the character's avatar.
Create an AvatarPhysicsAssetComponent
by creating a child class of M2M_AvatarPhysicsAssetComponent
.
The important fields are:
Avatar Physics Asset Data: This configures which physics asset the character should use on remote clients. This is covered in the next section.
Interaction Query/Collision Channel: These are the channels that are dynamically enabled/disabled (by being set to ignore or block) by this component according to your configuration, to be used for your gameplay line tracing and collision. For example, these channels will be enabled and disabled on your character's Capsule according the configurations in this component.
Add this component to your Morpheus Character.
The Avatar Physics Asset Data controls which physics asset each character should be assigned on remote clients according to the avatar that character is currently using. Create an AvatarPhysicsAssetData
(a Data Asset) by creating a child Data Asset of M2_AvatarPhysicsAssetData
.
M2UP comes with some example AvatarPhysicsAssetData
assets for you to get started with right away, instead of creating your own:
DA_M2_HumanoidIfApplicable_PhysicsAssetData
: Assigns the character a humanoid physics asset if and only if the character's avatar is roughly humanoid shaped.
DA_M2_AlwaysHumanoid_PhysicsAssetData
: Always assigns the character a humanoid physics asset.
DA_M2_EmptyPhysicsAssetData
: Never assign a physics asset to the character. By default, this will enable the Interactable channels for your character's Capsule component.
Add an element into the Avatar Physics Asset Infos
array.
Ingame Physics Asset: The physics asset to assign this character if the character's avatar matches the Avatar Shape Rule.
Avatar Shape Rule: An asset representing a function that takes an avatar mesh as input and returns true or false, depending on whether the avatar matches this rule. Information on creating your own custom rule from scratch, or from customising M2UP's skeleton bounds rule is covered below. You can also use the example rules contained in M2UP: BP_M2_AlwaysValidAvatarShapeRule
and BP_M2_IsHumanoidAvatarShapeRule
. The latter should only match avatars which are approximately humanoid in shape.
Approximate Skeletal Mesh (Used only in the Crowd). The Skeletal Mesh asset that the Raycastable Crowd actor will use to represent this character, when this character is part of the crowd and its avatar matches this entry's rule. This should be a Skeletal Mesh asset that appropriately matches the Ingame Physics Asset.
As an example, if I want my character to be assigned PHYS_UE5Mannequin whenever their avatar matches the BP_M2_IsHumanoidAvatarShapeRule (i.e. when the avatar is approximately humanoid shaped and sized), the Physics Asset Info should look like this.
You can add multiple entries to the Avatar Physics Asset Infos array to match different physics assets to different characters depending on their avatar. In the case that multiple rules match an avatar, the first entry in the array that matches will be used.
However, using multiple avatar physics assets will limit the scale of your game, as there is currently a performance cost associated with swapping physics assets in pooled character actors.
To get the best performance out of high scale games, use a maximum of one entry in this array.
If a character uses an avatar that doesn't match any of the Avatar Physics Asset Infos, the function M2M_AvatarPhysicsAssetComponent.HandleInvalidPhysicsAsset
is invoked. By default, this enables the Capsule component to block the Interactable channels, but can be overridden.
The capsule component on M2 characters automatically resizes to match the mesh by default. More info on this can be found here.
You can use the Unreal show collision
command to view the physics assets in use. Your local player uses your mesh's generated physics asset, so to see the effects of the Avatar Physics Asset Component, start a PIE session with 2 clients. You should see that for each client, the remote character has been assigned a physics asset according to the rules.
M2 has a pre-configured SkelBoundsAvatarShapeRule that determines if an avatar fits between bounds which you can configure. Alternatively, you can write your own rule that derives from UM2_AvatarShapeRuleBase
.
The UM2_SkelBoundsAvatarShapeRule
is a rule that determines whether an avatar is between the bounds of two assets, with certain tolerances. This can be used to determine if an avatar is appropriate for a given physics asset.
For example, this is the the BP_M2_IsHumanoidAvatarShapeRule
that extends UM2_SkelBoundsAvatarShapeRule
.
Max/Min Physics Asset: The auto-generated physics asset for the user's mesh should be mostly within these bounds.
Reference Anim: This is the animation that will be used on the user's mesh to determine if the mesh is within bounds. This should be a neutral animation pose, like a T pose.
Voxel Edge Length: The comparison works by dividing the volume of the player's mesh into voxels and counting the number of voxels that are in or out of the bounds. This field determines how big these voxels are. Small voxels gives more accuracy but worse performance.
Required Min Coverage: The fraction of the minimum physics asset that must be covered by the user's mesh. Set to a higher value to be less tolerant of user mesh being smaller or not covering certain parts of the min physics asset.
Max Allowed Out Of Bounds: The fraction of the user's mesh that is allowed to be outside the max physics asset bounds. Set this to a lower number to be less tolerant of a user mesh being too large in parts compared to the max physics asset.
Debug Draw Voxels: Draw the voxels used for comparison, with voxels coloured according to if they are in or outside the bounds.
Debug Draw Collision Elements: Draw the comparison physics assets alongside the mesh's auto generated physics assets.
Alongside the Debug Draw settings, this rule will output in the LogM2AvatarPhysicsAsset
category to give additional information about why the rule did or did not match an avatar.
You can also access metadata about the result of the avatar rule matching on the local client (whether the avatars were too big, small, or a different error) in the UM2M_AvatarPhysicsAssetComponent.LocalAvatarShapeRuleResults
property.
You can also create your own custom Avatar Shape Rule. Create a child class that extends M2 Avatar Shape Rule Base
and override Does Avatar Shape Meet Rule
.
Here, you can write custom logic to determine if the input avatar skeleton should match the rule. The struct that is returned should contain IsValid=true
if this avatar did match the rule; the other properties are for observability purposes only.
DA_M2_HumanoidIfApplicable_PhysicsAssetData
physics data, which matches the humanoid robot avatar but not the big blobby avatar. We can see that from Blobby's client, the robot has a humanoid physics avatar, and from the robot's client, Blobby has not been assigned any physics avatar. Note that characters with invalid avatars may still sometimes appear with a physics avatar due to character pooling - this normally causes no issues as line queries are blocked by the enclosing capsule, but you can enable Unassign Physics Asset on Invalid Avatar
to change this behaviour.