Script to remove collider on some objects

Hi, I hope you will be able to help me and I hope this won’t be very hard for someone better than me in scripts. I have couple thousands trees with capsule collider (they are game objects). How can I remove collider on trees that are smaller than for example 0.2 in transform scale (need to do it in editor, not runtime) or second option is to change the layer to different one (they are on layer that detects collision now). Actually option number 2 would be better cause these are LODed and collider is on lod0 . Going one by one would be painful :frowning: Much appreciate your help :slight_smile:

Write an editor script that finds all Capsule colliders and checks their size, then does a DestroyImmediate() on the small ones, or else change the layer on the small ones, your choice.

It really is that easy. Start with Unity - Scripting API: EditorWindow

Welcome to Unity editor scripting… unbelievably powerful.

Be sure to call Undo.RecordObject() so the scene or prefab gets “dirtied” so you can save it.

2 Likes

and unbelievably poorly executed. It’s horrific. Your problem sounds simple enough, just stay patient if you get stuck or something makes no sense whatsoever.

Thanks, never created any editor script, looks like it’s time for first one :smile:

Excellent! I think @Dextozz is exaggerating just a little bit above :slight_smile: but I respect that he’s probably been bitten by the same weirdnesses that I have.

The editor scripting area is definitely a complex API but it does a lot, and while there are certainly some warts and weirdnesses to beware of, most of the time you can get where you need to be, especially with a simple task like above.

In your case, just beware whether you are modifying the copy of the GameObject in scene, or else the prefab on disk. They are not the same, so pay attention!

1 Like