ForceLOD(int)
Disable automatic LOD selection based on camera distance by forcing a specific LOD level, or revert to the default automatic behavior by passing a negative value as parameter.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public void ForceLOD(int index)
Parameters
The LOD level to use. Passing a negative index value enables automatic LOD selection.
Remarks
This method specifies explicitly which LOD level Unity should use. You can achieve the same result in a script by disabling the component and renderers of the unneeded LOD levels, but using the method provides slightly better CPU performance. This is relevant if you need to force a particular LOD state only for a few frames. This method lets you avoid storing the original states of the renderers when you force an LOD level.
LODGroupForceLODIf you need to force a particular LOD level for a large number of LODGroups for a large number of frames, the alternative approach of disabling the and renderers might provide better CPU performance.
LODGroupExamples
using UnityEngine;public class SampleScript : MonoBehaviour{ public bool isHero = false; private LODGroup m_LODGroup; void Start() { m_LODGroup = GetComponent<LODGroup>(); } void Update() { if (!m_LODGroup) return; // Force LOD to highest quality level (0) when in hero mode // Else enable automatic LOD selection (-1). m_LODGroup.ForceLOD(isHero ? 0 : -1); }}