- Home /
How can i find all *_LOD1 objects in a scene?
There is a bug where the physics act weird because the automatic LOD meshes also have many collision meshes instead of a single shared one. Basicly it makes everything more slippery then it needs to be.
Since I don't have high hopes for a fix on this matter, I want to try and have a script that automaticly disables the collision mesh for all gameobjects named *LOD1 *LOD2 and *LOD3 as that fixes the problem I have.
Now I understand how to find a gameobject with a specific name, but how can I find gameobjects with a specific part of their name?
Answer by hiddenspring81 · May 22, 2013 at 05:14 PM
Use Resources.FindObjectsOfTypeAll. This will return all of the objects that have been loaded into memory, of a given type.
// Build a list of all Meshes that exist in memory
var loadedMeshes = Resources.FindObjectsOfTypeAll(typeof(Mesh));
foreach (var mesh in loadedMeshes)
{
// Find only those meshes that in LOD1, LOD2, or LOD3
if (mesh.name.EndsWith("LOD1")|| mesh.name.EndsWith("LOD2") || mesh.name.EndsWith("LOD3"))
{
// Turn off the mesh collider
mesh.collider.enabled = false;
}
}
Just be careful with when you call Resources.FindObjectsOfTypeAll
because it's extremely expensive, computationally.
Thanks, I will be using it as an editor script to quicky update all lod models in a scene.
Here is my editor script based on @hiddenspring81 his awnser for who can use it:
class SD_Lod$$anonymous$$anager extends ScriptableWizard
{
var scrollPosition :Vector2;
//-------------------------------------------------------------------------------------------------------------------------------
new function OnGUI() :void
{
scrollPosition = GUILayout.BeginScrollView (scrollPosition);
GUILayout.Space (10);
if(GUILayout.Button("Disable lower lod colliders"))
{
EnableLodCollision(false);
}
if(GUILayout.Button("Enable lower lod collisions"))
{
EnableLodCollision(true);
}
GUILayout.Space (20);
if(GUILayout.Button("Close"))
{
this.Close();
}
GUILayout.EndScrollView ();
}
//-------------------------------------------------------------------------------------------------------------------------------
@$$anonymous$$enuItem("Lod Collider manager")
static function Init() :void
{
var window :SD_Lod$$anonymous$$anager = EditorWindow.GetWindow(SD_Lod$$anonymous$$anager, false, "Lod $$anonymous$$anager");
}
//-------------------------------------------------------------------------------------------------------------------------------
function EnableLodCollision(enabled :boolean) :void
{
// Create an array that has all colliders in the scene.
var colliders :Collider[] = FindObjectsOfType(Collider) as Collider[];
for(var col :Collider in colliders)
{
// Find only those meshes that in LOD1, LOD2, or LOD3
if (col.name.EndsWith("LOD1") || col.name.EndsWith("LOD2") || col.name.EndsWith("LOD3"))
{
// Turn off the mesh collider
//Debug.Log(col.name);
col.enabled = enabled;
}
}
}
}
Your answer

Follow this Question
Related Questions
Getting Objects from CheckSphere 0 Answers
Find all objects inside box collider 4 Answers
heightmapMaximumLOD does not refresh the terrain collider? 0 Answers
Find closest point of a sprite to GameObject 2D 1 Answer
Find right mesh for collider 1 Answer