Skip to content

Instantly share code, notes, and snippets.

@dimmduh
Created January 16, 2023 08:22
Show Gist options
  • Save dimmduh/c5fddd1db46d015929e85fd99b135390 to your computer and use it in GitHub Desktop.
Save dimmduh/c5fddd1db46d015929e85fd99b135390 to your computer and use it in GitHub Desktop.
[MenuItem(z_EditorPrefs.ContextMenuInHierarchyCommonPath + "/Fix Before export FBX", false)]
public static void FixBeforeExportFbx()
{
if (!Selection.activeGameObject)
{
return;
}
foreach (var gameObject in Selection.gameObjects)
{
gameObject
.GetComponentsInChildren<SkinnedMeshRenderer>()
.ForEach(renderer =>
{
if (renderer != null)
Object.DestroyImmediate(renderer);
});
}
foreach (var gameObject in Selection.gameObjects)
{
gameObject
.GetComponentsInChildren<LODGroup>(true)
.ForEach(group =>
{
Debug.Log($"Go to {group.gameObject.name}", group.gameObject);
var lods = group.GetLODs().ToList();
var newLods = new List<LOD>(lods.Count);
lods.ForEach(lod =>
{
var was = lod.renderers.Length;
lod.renderers = lod.renderers.WhereNotNull().ToArray();
newLods.Add(lod);
var now = lod.renderers.Length;
if (was != now)
Debug.Log("Null lod renderer", group.gameObject);
});
group.SetLODs(newLods.ToArray());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment