Visualization with Mass Framework

Published on

How to process visualization with Mass Framework. Mass Framework is a ECS for managing crowds and traffic in Unreal 5.0 and above.

Platforma

Processing Visualization with MassGameplay built-in resources

Visualization traits help to manage the visual aspects of rendering and processing entities. They are part of MassGameplay buil-in plugin.

Visualization Traits inheritance

Visualization Traits work uses following fragments (beside others):

  • FMassRepresentationFragment informing about LODs matters
    USTRUCT()
    struct MASSREPRESENTATION_API FMassRepresentationFragment : public FMassFragment
    {
    	GENERATED_BODY()
    
    	EMassRepresentationType CurrentRepresentation = EMassRepresentationType::None;
    
    	EMassRepresentationType PrevRepresentation = EMassRepresentationType::None;
    
    	int16 HighResTemplateActorIndex = INDEX_NONE;
    
    	int16 LowResTemplateActorIndex = INDEX_NONE;
    
    	int16 StaticMeshDescIndex = INDEX_NONE;
    
    	FMassActorSpawnRequestHandle ActorSpawnRequestHandle;
    
    	FTransform PrevTransform;
    
    	/** Value scaling from 0 to 3, 0 highest LOD we support and 3 being completely off LOD */
    	float PrevLODSignificance = -1.0f;
    };
  • FMassRepresentationLODFragment informing about entities visibility
    USTRUCT()
    struct MASSREPRESENTATION_API FMassRepresentationLODFragment : public FMassFragment
    {
    	GENERATED_BODY()
    
    	/** LOD information */
    	TEnumAsByte<EMassLOD::Type> LOD = EMassLOD::Max;
    	TEnumAsByte<EMassLOD::Type> PrevLOD = EMassLOD::Max;
    
    	/** Visibility Info */
    	EMassVisibility Visibility = EMassVisibility::Max;
    	EMassVisibility PrevVisibility = EMassVisibility::Max;
    
    	/** Value scaling from 0 to 3, 0 highest LOD we support and 3 being completely off LOD */
    	float LODSignificance = 0.0f;
    };
  • FMassViewerInfoFragment - specifies viewer and frustrum distance
    USTRUCT()
    struct MASSLOD_API FMassViewerInfoFragment : public FMassFragment
    {
    	GENERATED_BODY()
    
    	// Closest viewer distance
    	float ClosestViewerDistanceSq;
    
    	// Closest distance to frustum
    	float ClosestDistanceToFrustum;
    };

Visualization Trait

Built-in MassGameplay Trait located At UE5/Engine/Plugins/Runtime/MassGameplay/Source/MassRepresentation

Visualization Trait

Visualization trait shared fragment options offers the option of using a static mesh instance or actors.

For the building simulation example, there's sufficient to only use instance static meshes, as there's not an expectation that the camera to get close enough to the agents.

For a project where the camera can really go close to characters, it will be better to have a high and low actor version and mix that solution with a static mesh instance.

The visualization processor needs some fragments that are not added in the trait that we are using. And that's why we have a trait called Assorted Fragments that allow us to add specific fragments.

Mass Visualization System

In this case, we're adding the Mass Viewer Info Fragment and the Mass Actor Fragment in case we want to have actors visualized.

Visualization Trait / Crowd Visualization Trait

A Trait extending default Visualization Trait.

UCLASS(BlueprintType, EditInlineNew, CollapseCategories, meta=(DisplayName="Crowd Visualization"))
class MASSCROWD_API UMassCrowdVisualizationTrait : public UMassVisualizationTrait
{
	GENERATED_BODY()
public:
	UMassCrowdVisualizationTrait();

	virtual void BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const override;
};
Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us