Version: 5.4 beta (switch to 5.3)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

CullingGroup.SetBoundingDistances

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function SetBoundingDistances(distances: float[]): void;
public void SetBoundingDistances(float[] distances);

Parameters

distances An array of bounding distances. The distances should be sorted in increasing order.
distanceBehaviours An array of CullingDistanceBehaviour settings. The array should be the same length as the array provided to the distances parameter. It can also be omitted or passed as null, in which case all distances will be given CullingDistanceBehaviour.Normal behaviour.

Description

Set bounding distances for 'distance bands' the group should compute, as well as options for how spheres falling into each distance band should be treated.

Each distance value indicates a band that is 'up to' that distance; the array [10, 20, 30] describes distance bands "from 0 to 10m", "from 10m to 20m" and "from 20m to 30m."

The distance from the reference point (set by CullingGroup.SetDistanceRefPoint) to the nearest edge of the sphere is used to calculate which distance band a sphere is in. Therefore a sphere that covers multiple distance bands will be considered to be in the nearest one to the reference point.

The distanceBehaviours array describes how a sphere being in a given distance band should have its culling modified. For example, you might force any object within 20m to be visible even if it is behind the camera (to ensure that characters behind the player are still running full animation, audio, etc) while forcing any object beyond 200m to be invisible (effectively, culling spheres based on distance).

In addition to forcing objects to be visible or invisible, you can use distance bands to drive level-of-detail changes in your objects. For example, you might define bands "from 0 to 40m" and "from 40m to 80m", and while you might have both bands apply occlusion and frustum culling as normal, you could have objects in the second band be animated with a less complex rig, or run a less complex AI behaviour.

By default, any spheres beyond the final bounding distance are implicitly forced to be invisible. To avoid this, you can specify a final bounding distance of float.PositiveInfinity.