FX.MaxCPUParticlesPerEmitter

FX.MaxCPUParticlesPerEmitter

#Overview

name: FX.MaxCPUParticlesPerEmitter

This variable is created as a Console Variable (cvar).

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of FX.MaxCPUParticlesPerEmitter is to set the maximum number of CPU particles allowed per emitter in Unreal Engine’s particle system. This setting is crucial for managing performance and memory usage in the engine’s visual effects (FX) system.

This setting variable is primarily used by the particle system within Unreal Engine’s rendering module. Based on the callsites, it’s clear that this variable is utilized in the FXSystem and ParticleEmitterInstances components of the engine.

The value of this variable is set in the FXConsoleVariables namespace, initialized to 1000. It can be modified at runtime through the console variable system, as evident from the FAutoConsoleVariableRef declaration.

The associated variable MaxCPUParticlesPerEmitter directly interacts with FX.MaxCPUParticlesPerEmitter. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable sets a hard limit on the number of CPU particles per emitter. If an emitter attempts to spawn more particles than this limit, the excess particles will not be created. This can affect the visual quality of particle effects if set too low.

Best practices when using this variable include:

  1. Carefully balancing between performance and visual quality when adjusting this value.
  2. Monitoring performance impact when increasing this value, as higher values can lead to increased CPU usage.
  3. Using this in conjunction with other particle system optimizations for best results.
  4. Considering the target hardware when setting this value, as lower-end systems may require a lower limit.

Regarding the associated variable MaxCPUParticlesPerEmitter:

The purpose of MaxCPUParticlesPerEmitter is identical to FX.MaxCPUParticlesPerEmitter, serving as the internal representation of the maximum CPU particles per emitter.

This variable is used directly in the particle system code, particularly in the FParticleEmitterInstance::Spawn function, where it’s used to limit the number of particles spawned.

The value is set in the FXConsoleVariables namespace and can be modified through the console variable system.

It directly interacts with FX.MaxCPUParticlesPerEmitter, sharing the same value.

Developers should be aware that modifying this variable directly in code might not reflect changes made through the console variable system, and vice versa.

Best practices include using the console variable FX.MaxCPUParticlesPerEmitter for runtime adjustments rather than modifying MaxCPUParticlesPerEmitter directly, to ensure consistency across the engine.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/FXSystem.cpp:182

Scope (from outer to inner):

file
namespace    FXConsoleVariables

Source code excerpt:

		);
	FAutoConsoleVariableRef CVarMaxCPUParticlesPerEmitter(
		TEXT("FX.MaxCPUParticlesPerEmitter"),
		MaxCPUParticlesPerEmitter,
		TEXT("Maximum number of CPU particles allowed per-emitter.")
		);
	FAutoConsoleVariableRef CVarMaxGPUParticlesSpawnedPerFrame(
		TEXT("FX.MaxGPUParticlesSpawnedPerFrame"),
		MaxGPUParticlesSpawnedPerFrame,

#Associated Variable and Callsites

This variable is associated with another variable named MaxCPUParticlesPerEmitter. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/FXSystem.cpp:129

Scope (from outer to inner):

file
namespace    FXConsoleVariables

Source code excerpt:

	float ParticleSlackGPU = 0.02f;
	int32 MaxParticleTilePreAllocation = 100;
	int32 MaxCPUParticlesPerEmitter = 1000;
	int32 MaxGPUParticlesSpawnedPerFrame = 1024 * 1024;
	int32 GPUSpawnWarningThreshold = 20000;
	float GPUCollisionDepthBounds = 500.0f;
	TAutoConsoleVariable<int32> TestGPUSort(TEXT("FX.TestGPUSort"),0,TEXT("Test GPU sort. 1: Small, 2: Large, 3: Exhaustive, 4: Random"),ECVF_Cheat);

	/** Register references to flags. */

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/FXSystem.cpp:183

Scope (from outer to inner):

file
namespace    FXConsoleVariables

Source code excerpt:

	FAutoConsoleVariableRef CVarMaxCPUParticlesPerEmitter(
		TEXT("FX.MaxCPUParticlesPerEmitter"),
		MaxCPUParticlesPerEmitter,
		TEXT("Maximum number of CPU particles allowed per-emitter.")
		);
	FAutoConsoleVariableRef CVarMaxGPUParticlesSpawnedPerFrame(
		TEXT("FX.MaxGPUParticlesSpawnedPerFrame"),
		MaxGPUParticlesSpawnedPerFrame,
		TEXT("Maximum number of GPU particles allowed to spawn per-frame per-emitter.")

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/ParticleEmitterInstances.cpp:2074

Scope (from outer to inner):

file
function     float FParticleEmitterInstance::Spawn

Source code excerpt:

		int32 NewCount = ActiveParticles + Number + BurstCount;

		if (NewCount > FXConsoleVariables::MaxCPUParticlesPerEmitter)
		{
			int32 MaxNewParticles = FXConsoleVariables::MaxCPUParticlesPerEmitter - ActiveParticles;
			BurstCount = FMath::Min(MaxNewParticles, BurstCount);
			MaxNewParticles -= BurstCount;
			Number = FMath::Min(MaxNewParticles, Number);
			NewCount = ActiveParticles + Number + BurstCount;
		}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/FXSystem.h:77

Scope (from outer to inner):

file
namespace    FXConsoleVariables

Source code excerpt:

	extern int32 MaxParticleTilePreAllocation;
	/** Maximum number of CPU particles to allow per-emitter. */
	extern int32 MaxCPUParticlesPerEmitter;
	/** Maximum number of GPU particles to spawn per-frame. */
	extern int32 MaxGPUParticlesSpawnedPerFrame;
	/** Warning threshold for spawning of GPU particles. */
	extern int32 GPUSpawnWarningThreshold;
	/** Depth bounds for GPU collision checks. */
	extern float GPUCollisionDepthBounds;