I have a scene with over 1000 static game objects, all with colliders attached. I need to combine meshes to improve performance, but when I use simpleLOD to combine meshes, the colliders are gone.
Is there a way to get all colliders in a scene and put them on empty game objects? That way, when I combine meshes, I will still have the colliders. Any other ideas are welcome.
sounds like you’re either going to need to:
a: do it manually one at a time by copying the component into a new empty game object or
b: write an editor script to do it for you.
with a 1000, I’d try option B
Thanks, I’m going with option B. It seems the colliders are not gone, but since the child game objects are turned off, their colliders are as well. All I need to do is get the components in children and setactive, then turn off the mesh and anything else that’s not a collider.
Here is my temporary solution:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(turn_on_colliders))]
public class Colliders_Script : Editor
{
turn_on_colliders colliderscript;
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUILayout.Button("show_colliders"))
{
colliderscript.turn_them_on();
}
}
}
where it accesses this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class turn_on_colliders : MonoBehaviour
{
public void turn_them_on()
{
Component[] components = GetComponentsInChildren(typeof(Transform), true);
foreach (Component child_object in components)
{
child_object.gameObject.SetActive(true);
}
Component[] meshChildren = GetComponentsInChildren(typeof(MeshRenderer), true);
foreach (MeshRenderer mesh in meshChildren)
{
mesh.enabled = false;
}
}
}