SimulationLOD in Mass Framework

How does SimulationLOD work in Mass Framework? Mass Framework is an ECS for managing crowds and traffic, available since Unreal Engine 5.0. Engine code excerpts below were taken from UE 5.3 - check the source of your engine version (UE 5.8) for implementation details.

Vladimír NeporAuthorVladimír Nepor
Published

SimulationLOD with MassGameplay built-in resources

  • SimulationLOD Trait

    • Built-in MassGameplay.
    • Trait located At UE5/Engine/Plugins/Runtime/MassGameplay/Source/MassLOD.
    • SimulationLOD trait shares the same Trait file with LODCollector.
    void UMassSimulationLODTrait::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
    {
    	BuildContext.RequireFragment<FMassViewerInfoFragment>();
    	BuildContext.RequireFragment<FTransformFragment>();
    
    	FMassSimulationLODFragment& LODFragment = BuildContext.AddFragment_GetRef<FMassSimulationLODFragment>();
    
    	// Start all simulation LOD in the Off 
    	if(Params.bSetLODTags || bEnableVariableTicking)
    	{
    		LODFragment.LOD = EMassLOD::Off;
    		BuildContext.AddTag<FMassOffLODTag>();
    	}
    
    	FMassEntityManager& EntityManager = UE::Mass::Utils::GetEntityManagerChecked(World);
    
    	FConstSharedStruct ParamsFragment = EntityManager.GetOrCreateConstSharedFragment(Params);
    	BuildContext.AddConstSharedFragment(ParamsFragment);
    
    	uint32 ParamsHash = UE::StructUtils::GetStructCrc32(FConstStructView::Make(Params));
    	FSharedStruct SharedFragment = EntityManager.GetOrCreateSharedFragmentByHash<FMassSimulationLODSharedFragment>(ParamsHash, Params);
    	BuildContext.AddSharedFragment(SharedFragment);
    	// Variable ticking from simulation LOD
    	if(bEnableVariableTicking)
    	{
    		BuildContext.AddFragment<FMassSimulationVariableTickFragment>();
    		BuildContext.AddChunkFragment<FMassSimulationVariableTickChunkFragment>();
    
    		FConstSharedStruct VariableTickParamsFragment = EntityManager.GetOrCreateConstSharedFragment(VariableTickParams);
    		BuildContext.AddConstSharedFragment(VariableTickParamsFragment);
    
    		uint32 VariableTickParamsHash = UE::StructUtils::GetStructCrc32(FConstStructView::Make(VariableTickParams));
    		FSharedStruct VariableTickSharedFragment = EntityManager.GetOrCreateSharedFragmentByHash<FMassSimulationVariableTickSharedFragment>(VariableTickParamsHash, VariableTickParams);
    		BuildContext.AddSharedFragment(VariableTickSharedFragment);
    	}
    }
    

Anything unclear?

Let us know!

Contact Us