- Home /
Disable collider automaticly for lodgroups?
Can I have the collider for lower detail meshes in a lodgroup have automaticly disable the mesh collider?
For example having a lodgroup with 3 meshes means there are 3 collider meshes in roughly the same space while I would only need 1.
This leads to alot of unexpected behavior like invisible walls caused by a lower lod model collider and also weird physics behavior in my ball physics game.
Like surfaces being slippery that aren't that fix themselves if i disable a lod collider.
Having to go trough every model in my levels will take alot of time so i wonder if I can tell the fbx importer to have the lodgroups lower detail meshes have no collider.
I don't know if there is a better way but I would consider using a sphere trigger and just use OnTriggerEnter/Exit to do the job.
I ended up writing a script that disables colliders on lower lod meshes in the scene.
Answer by ZiadJ · May 24, 2015 at 02:44 PM
LODGroups only seem to be able to work on renderers in Unity3d. A workaround is to attach a script to the parent gameobject that will disable all child colliders by name at startup. Here's a sample method you can use to achieve it:
private void DisableCollidersRecursive<T>(string nameMatcher = null) where T : Collider
{
Regex matcher = string.IsNullOrEmpty(nameMatcher) ? null : new Regex(nameMatcher);
foreach (var collider in gameObject.GetComponentsInChildren<T>())
if (matcher == null || matcher.IsMatch(collider.gameObject.name))
collider.enabled = false;
}
For instance you might set the input parameter as ".*_LOD1" to target only first level LODs.
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Collider Activate Trigger Animation 0 Answers
OnTriggerEnter not being called with multiple colliders 1 Answer
C# Check if Collider2D[] Doesn't contain Scripted GameObject 1 Answer
Attempt counter 2 Answers