为何触发Assertion failed异常?求含义解析与修复方案
Hey there, let's dig into this Unity assertion error you're facing. First off, let's break down what this message actually means:
This is an internal Unity assertion failure—essentially, the engine had a safety check in place that assumed a certain scenario should never occur, but it did anyway. The core issue here is that Unity's lighting system encountered a "radiosity system" (a component tied to how baked light interacts with objects) whose radiosity hash doesn't exist in your project's LightmapSettings. The engine says it already filtered out these invalid systems, but somehow one slipped through, triggering this error.
Common Causes
Before jumping to fixes, let's cover why this might happen:
- Corrupted baked light data: Your lightmaps or their associated metadata might have become damaged, creating a mismatch between the light data on objects and what's stored in
LightmapSettings. - Stale lightmap references: You might have deleted baked lightmap files, but the objects in your scene still retain references to the old radiosity hashes that no longer exist in
LightmapSettings. - Multi-scene loading/unloading issues: If you're working with multiple scenes, improper cleanup during scene transitions can leave behind invalid lighting system references that aren't properly filtered.
- Pipeline/plugin conflicts: Custom render pipelines (like outdated URP/HDRP versions) or third-party lighting plugins might be modifying
LightmapSettingsor radiosity data in unexpected ways, bypassing Unity's built-in filters.
Step-by-Step Fixes
Let's go through actionable steps to resolve this:
Full Lightmap Cleanup & Rebake
- First, delete all existing baked lightmap files from your project (usually in a
Lightmapsfolder in your Project window). - Open the Lighting Settings window (
Window > Rendering > Lighting Settings), click theClear Baked Databutton to wipe all cached lighting data. - Rebake your scene's lighting from scratch. This ensures all radiosity hashes are regenerated and properly synced with
LightmapSettings.
- First, delete all existing baked lightmap files from your project (usually in a
Audit Object Lightmap Components
- Select all objects in your scene that use baked lighting (you can use the Hierarchy search bar with
t:MeshRendererto filter them). - Check the Inspector for each object's
Lightmap Staticsettings. Look for any grayed-out or missing lightmap references—these are signs of invalid radiosity hash links. - For problematic objects, disable and re-enable
Lightmap Static, or reset the MeshRenderer component to clear stale references.
- Select all objects in your scene that use baked lighting (you can use the Hierarchy search bar with
Validate LightmapSettings Configuration
- In the Lighting Settings window, scroll to the
Lightmapssection. Check if any entries in the list show missing or invalid icons. - Remove any invalid lightmap entries from the list, then re-bake to regenerate valid entries.
- In the Lighting Settings window, scroll to the
Fix Multi-Scene Lighting Cleanup
- If you're using multi-scene workflows, ensure you're properly cleaning up lighting data when unloading scenes. You can add code like
Lightmapping.ClearDiskCache()in your scene unloading logic to clear stale cached data. - Avoid unloading scenes while baking is in progress, as this can leave partial, invalid lighting data behind.
- If you're using multi-scene workflows, ensure you're properly cleaning up lighting data when unloading scenes. You can add code like
Check for Plugin/Pipeline Conflicts
- Temporarily disable all third-party lighting-related plugins, then test if the error still occurs. If it goes away, re-enable plugins one by one to identify the culprit.
- If you're using a custom render pipeline, try switching back to the built-in pipeline temporarily to rule out pipeline-specific bugs. If that works, update your pipeline to the latest stable version.
Reset LightmapSettings via Editor Script
- If all else fails, you can reset
LightmapSettingsto default values using a simple Editor script:using UnityEditor; using UnityEngine.Rendering; public class ResetLightmapSettings : EditorWindow { [MenuItem("Tools/Reset Lightmap Settings")] public static void ShowWindow() { LightmapSettings.Reset(); Debug.Log("Lightmap Settings reset to default"); } } - Run this script, reconfigure your lighting settings, then re-bake.
- If all else fails, you can reset
Bonus Tips
- Always back up your project before performing major cleanup or resets to avoid data loss.
- If you're on an older Unity version, consider updating to the latest stable release—this might be a known bug that's been fixed in newer versions.
内容的提问来源于stack exchange,提问作者Daniel Lip

