RealDocs

UGameplayStatics::GrassOverlappingSphereCount

function Engine Blueprint Since 4.8
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticBlueprintCallable

Description

Returns the number of procedural grass foliage instances of a given static mesh that overlap a sphere. Useful for gameplay systems that need to know foliage density, such as hiding actors in tall grass.

Caveats & Gotchas

  • Marked UnsafeDuringActorConstruction — do not call from constructors or OnConstruction; call from BeginPlay or later in the frame.
  • Only counts grass foliage painted or generated via the Foliage Tool or Procedural Foliage Volume — manually placed static mesh actors are not included regardless of their mesh.
  • Performance scales with foliage density and query radius; avoid calling every frame over large radii in dense foliage scenes.

Signature

static ENGINE_API int32 GrassOverlappingSphereCount(const UObject* WorldContextObject, const UStaticMesh* StaticMesh, FVector CenterPosition, float Radius);

Parameters

Name Type Description Default
WorldContextObject const UObject* Any UObject within the world to provide world context.
StaticMesh const UStaticMesh* The static mesh type to count; only foliage instances using this exact mesh are counted.
CenterPosition FVector Center of the query sphere in world space.
Radius float Radius of the query sphere in centimeters.

Return Type

int32

Example

Check if player is hidden in tall grass C++
int32 GrassCount = UGameplayStatics::GrassOverlappingSphereCount(
    this,
    TallGrassMesh,
    Player->GetActorLocation(),
    100.f
);
bool bHiddenInGrass = (GrassCount >= 3);

Version History

Introduced in: 4.8

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.