Add LOD cross-fade support, null safety, and consistent LODGroup initialization#4
Open
Copilot wants to merge 2 commits into
Open
Add LOD cross-fade support, null safety, and consistent LODGroup initialization#4Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…Cache() Co-authored-by: YvesAlbuquerque <38794389+YvesAlbuquerque@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve Unity LOD integration
Add LOD cross-fade support, null safety, and consistent LODGroup initialization
Mar 11, 2026
There was a problem hiding this comment.
Pull request overview
This PR adds configurable LOD cross-fade behavior across AutoLOD’s LODGroup creation paths, improves null-safety when working with renderer arrays, and introduces a cache invalidation API for LODGroupHelper to prevent stale derived data.
Changes:
- Introduces
LODFadeModeandanimateCrossFadingsettings in project preferences and import settings, and applies them when creating/configuringLODGroups. - Adds null-safety around LOD renderer arrays (filtering null renderers before
SetLODs, and guarding null arrays during iteration). - Adds
LODGroupHelper.InvalidateCache()to allow external callers to flush cached LODGroup-derived state.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Runtime/LODVolume_Editor.cs | Applies fade mode + cross-fade animation settings when generating scene/volume LODGroups. |
| Runtime/LODImportSettings.cs | Adds fade mode + animate cross-fading fields to per-asset import settings. |
| Runtime/LODGroupHelper.cs | Adds InvalidateCache() for flushing cached LODGroup-derived values. |
| Runtime/Extensions/LODGroupExtensions.cs | Adds null guards when enabling/disabling renderers via LOD arrays. |
| Runtime/AutoLODSettingsData.cs | Stores fade mode + cross-fade animation settings and exposes them via properties. |
| Editor/ModelImporterLODGenerator.cs | Filters null renderers, uses consistent ForceLOD init pattern, and applies fade settings on import-created LODGroups. |
| Editor/LODDataEditor.cs | Syncs fade settings into per-model import settings when toggling defaults/overrides. |
| Editor/Extensions.cs | Adds null guard for lod.renderers in HasLODChain(). |
| Editor/AutoLODSettings.cs | Adds Preferences UI for selecting LOD fade mode and cross-fade animation. |
| Editor/AutoLOD.cs | Applies fade settings when generating LODGroups from the menu workflow. |
| CHANGELOG.md | Documents the new fade settings, cache invalidation, and null-safety fixes. |
Comments suppressed due to low confidence (1)
Editor/LODDataEditor.cs:50
LODImportSettingsnow containsfadeModeandanimateCrossFading, but the customLODImportSettingsDrawercurrently does not render these fields. As a result, whenOverride Defaultsis enabled, the per-model import settings UI won’t allow editing the new fade settings (and the PR description’s “per-model override” isn’t actually achievable). Update the drawer to display these properties (and ideally only showanimateCrossFadingwhen fade mode != None, matching Preferences).
m_ImportSettings.FindPropertyRelative("fadeMode").enumValueIndex = (int)autoLODSettingsData.FadeMode;
m_ImportSettings.FindPropertyRelative("animateCrossFading").boolValue = autoLODSettingsData.AnimateCrossFading;
}
if (settingsOverridden)
{
EditorGUILayout.PropertyField(m_ImportSettings, new GUIContent("Import Settings"), true);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,5 @@ | |||
| using System; | |||
| using UnityEngine; | |||
| using UnityEngine.Serialization; | |||
Comment on lines
+69
to
+79
| /// <summary> | ||
| /// Invalidates all cached LODGroup data, forcing it to be re-fetched on next access. | ||
| /// Call this after modifying the LODGroup's LODs, transform, or size externally. | ||
| /// </summary> | ||
| public void InvalidateCache() | ||
| { | ||
| m_LODs = null; | ||
| m_ReferencePoint = null; | ||
| m_WorldSpaceSize = null; | ||
| m_MaxLOD = null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AutoLOD creates
LODGroupcomponents across three code paths but never configures fade mode, uses inconsistent initialization patterns, and lacks null guards on renderer arrays.LOD fade mode
LODFadeModeandanimateCrossFadingsettings inAutoLODSettingsData,LODImportSettings, and the Preferences UIAutoLOD.GenerateLODs,ModelImporterLODGenerator.CreateLODGroup,LODVolume_Editor.GenerateHLOD/GenerateLODsLODDataEditorinspector syncs fade settingsConsistent LODGroup initialization
ModelImporterLODGenerator.CreateLODGroupnow uses theForceLOD(0)/SetLODs/RecalculateBounds/ForceLOD(-1)pattern already used inAutoLOD.cs, ensuring deterministic initial LOD state.Null safety
ModelImporterLODGenerator.CreateLODGroup: filters null renderers from LOD arrays beforeSetLODsExtensions.HasLODChain: guardslod.renderersfor null before.LengthLODGroupExtensions.SetRenderersEnabled: early-returns on nulllods, skips nullrenderersLODGroupHelper.InvalidateCache()
New public method to flush all cached derived state (
m_LODs,m_ReferencePoint,m_WorldSpaceSize,m_MaxLOD). The setter already does this on reassignment, but external callers modifying the underlyingLODGroupdirectly had no way to reset stale cache.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.