Skip to content

Instantly share code, notes, and snippets.

@twobob
Created April 13, 2017 01:07
Show Gist options
  • Save twobob/90fb93504b4c7076818a5de393773fdb to your computer and use it in GitHub Desktop.
Save twobob/90fb93504b4c7076818a5de393773fdb to your computer and use it in GitHub Desktop.
For clearing down the blank mesh renderers from ProDrawCall - Works on Selected items + children
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.Linq;
// Select some Gameobjects in the scene view to use this
public class RipOrphanRenderers {
[MenuItem("Window/Remove Orphaned Disabled Renderers")]
static void RipOrphans()
{
var objs = Selection.gameObjects;
foreach (var go in objs) {
foreach(Transform child in go.transform)
{
if ( child.gameObject.name.Contains ("LOD")) {
MeshRenderer mr = child.gameObject.GetComponent<MeshRenderer> ();
if (mr != null) {
if (!mr.enabled) {
SafeDestroy ( child.gameObject);
}
}
}
}
}
}
public static T SafeDestroy<T>(T obj) where T : Object
{
if (Application.isEditor)
Object.DestroyImmediate(obj);
else
Object.Destroy(obj);
return null;
}
public static T SafeDestroyGameObject<T>(T component) where T : Component
{
if (component != null)
SafeDestroy(component.gameObject);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment