Crowd Visualization trait in Mass Framework

Published on

How does Crowd Visualization Trait works in Mass Framework? Mass Framework is a ECS for managing crowds and traffic in Unreal 5.0 and above.

Platforma

Crowd Visualization Trait

City Sample - Mass Entity Config Asset

Setup:

  • Params

    • RepresentationActorManagementClass: Class for adjusted controlling of spawned Actors, such as position adjustments
      // Copyright Epic Games, Inc. All Rights Reserved.
      #pragma once
      
      #include "MassCrowdRepresentationActorManagement.h"
      
      #include "SampleMassCrowdRepresentationActorManagement.generated.h"
      
      struct FMassEntityManager;
      class UMassCrowdSpawnerSubsystem;
      
      /**
      * Overridden actor management fro forsty specific
      */
      UCLASS(meta = (DisplayName = "Vrealmatic Crowd Visualization"))
      class VREALMATICSAMPLE_API USampleMassCrowdRepresentationActorManagement <strong>: public UMassCrowdRepresentationActorManagement</strong>
      {
      	GENERATED_BODY()
      
      	/**
      	* Method that will be bound to a delegate used post-spawn to notify and let the requester configure the actor
      	* @param SpawnRequestHandle the handle of the spawn request that was just spawned
      	* @param SpawnRequest of the actor that just spawned
      	* @param EntityManager to use to retrieve the mass agent fragments
      	* @return The action to take on the spawn request, either keep it there or remove it.
      	*/
      	virtual EMassActorSpawnRequestAction OnPostActorSpawn(const FMassActorSpawnRequestHandle& SpawnRequestHandle, FConstStructView SpawnRequest
      		, TSharedRef&lt;FMassEntityManager&gt; EntityManager) const override;
      
      	/**
      	 * Teleports the actor at the specified transform by preserving its velocity and without collision.
      	 * The destination will be adjusted to fit an existing capsule.
      	 * @param Transform is the new actor's transform
      	 * @param Actor is the actual actor to teleport
      	 * @param CommandBuffer to queue up anything that is thread sensitive
      	 */
      	 virtual void TeleportActor(const FTransform& Transform, AActor& Actor, FMassCommandBuffer& CommandBuffer) const override;
      };
      
      	
  • LODParams

    • LODMax Count

      • High: Maximum number of displayed entities with LODRepresentation::High
  • Overriding default value

    You may need to set Visualization trait values based on user preference, e.g. from the settings page. This can be done by overriding default values, see steps below:

    1. Creat a new derivated class of UMassCrowdVisualizationTrait trait and use it in the project instead of the default trait
    2. Use an override of the BuildTemplate
    #pragma once
    
    #include "CoreMinimal.h"
    #include "MassCrowdVisualizationTrait.h"
    #include "OccupantsVisualizationTrait.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class PATHFINDERIMPORTER_API UOccupantsVisualizationTrait : public UMassCrowdVisualizationTrait
    {
    	GENERATED_BODY()
    
    public:
    	UFUNCTION(BlueprintCallable, Category = "Visualization")
    	void SetLODMaxCountFromSession();
    
    	<mark>virtual void BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const override;</mark>
    };
Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us