x


Using the Unity Editor To Check "Convex" for Multiple Objects

So I'm trying to create a script to make my life a little easier without having to click every single object to add some physical properties. I have everything working except one thing.

I am trying to make all of my mesh colliders convex for my selected objects.

Here is what I have for code, which comes straight from the unity scripting reference, but it's still not working:

@MenuItem ("GameObject/SetConvex") static function setConvex () { Debug.Log ("Set object convex!!"); for (var i = 0; i < Selection.gameObjects.length; i++) { Selection.gameObjects[i].collider.convex = true; } }

This comes straight from unity's scripting reference found here: Script Reference

But every time I run the script I get an error which says that " 'convex' is not a member of UnityEngine.Collider'. "

Anyone got any ideas?

more ▼

asked Dec 08 '11 at 08:48 AM

Cnotey gravatar image

Cnotey
16 1 1 1

So I researched it, and convex is definitely a member of UnityEngine.Collider. Seriously, what the hell Unity? Anyone know a workaround?

Dec 08 '11 at 07:34 PM Cnotey

This seems to be an Android or iOS issue - code ran fine on WebPlayer but converting platforms yielded this error

Jan 02 '12 at 09:56 AM ina

convex is not a member of UnityEngine.Collider. It's a member of MeshCollider. A MeshCollider is also a Collider, but a Collider is not necessarily a MeshCollider.

@dannyskim 's answer is correct. UnityScript sometimes tries to figure out the type automatically, but it seems that doesn't work all the time. Also the language has changed a lot since the first release.

Jan 02 '12 at 01:16 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It may be documented that way on the link provided, but documentation isn't always right. I would take the compiler's word for it more so than documentation. In any case, it doesn't seem that the MeshCollider component is by default exposed to the user. I haven't done this myself, but most likely what you'll have to do is ( in c#):

for ( var i = 0; i < Selection.gameObjects.length; i++ )
{
     MeshCollider selectedCollider = Selection.gameObjects[i].GetComponent<MeshCollider>();
     selectedCollider.convex = true;
}

If you're using C# and are using MonoDevelop, Intellisense shows that collider does not inherit the member variable convex. Typically when you're programming environment tells you that a variable or component isn't exposed to you through Intellisense, it's usually right and not the documentation.

I haven't tested my code, but in theory it should do the trick.

EDIT: Also please use the insert code button, it would be very helpful in the future to read your code easier, no matter how short or long it may be.

more ▼

answered Dec 08 '11 at 10:59 PM

dannyskim gravatar image

dannyskim
3.9k 5 7 19

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x116

asked: Dec 08 '11 at 08:48 AM

Seen: 638 times

Last Updated: Jan 02 '12 at 01:16 PM