AddComponent to plane got error, what's wrong?

My code is:

plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
	plane.transform.parent = transform;
	plane.transform.localPosition = Vector3(0,-0.5,-0.5);
	plane.transform.localScale = Vector3(0.1,0.1,0.02);
	plane.AddComponent(MeshCollider);
	plane.GetComponent(MeshCollider).convex = true;
	
	plane.renderer.enabled = false;
	plane.AddComponent(Rigidbody);
	plane.rigidbody.mass = 1;
	plane.rigidbody.useGravity = true;
	plane.rigidbody.freezeRotation = true;
	
	plane.AddComponent(HingeJoint);
	
	plane.hingeJoint.connectedBody = rigidbody;
	
	hinge = plane.hingeJoint;

it ran well on my project. but when I tried it on another project, Unity shows these errors:

Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor’s mesh shapes! Please change mesh geometry or supply a tensor manually!
UnityEngine.Transform:set_parent(Transform)
UnityEngine.Transform:set_parent(Transform)
PullPillar:InitializePlane() (at Assets\Quan\PullPillar.js:21)
PullPillar:Start() (at Assets\Quan\PullPillar.js:14)

[\unity\stuff\external-source\physx\novodex\SDKs\Physics\src\NpActor.cpp line 150]

ConvexMesh::loadConvexHull: convex hull init failed!
UnityEngine.MeshCollider:set_convex(Boolean)
UnityEngine.MeshCollider:set_convex(Boolean)
UnityEngine.MeshCollider:MeshCollider$set_convex$System.Boolean(Object, Object[ ])
System.MulticastDelegate:invoke_object_object_object[ ](Object, Object[ ])
Boo.Lang.Runtime.RuntimeServices:smile:ispatch(Object, String, Type[ ], Object[ ], DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices:smile:ispatch(Object, String, Object[ ], DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices:SetProperty(Object, String, Object)
PullPillar:InitializePlane() (at Assets\Quan\PullPillar.js:25)
PullPillar:Start() (at Assets\Quan\PullPillar.js:14)

[\unity\stuff\external-source\physx\novodex\SDKs\Cooking\Src\ConvexMeshBuilder.cpp line 522]

what’s wrong with my code? How can I fix this?

:slight_smile:

You can’t apply a rigid body to a mesh that has no depth to it. You can change your plane to a box and it should work. The Physics system can’t deal with what is essentially a 2D object. It’s either that or the MeshCollider you’re trying to add, and then make convex.

Please test this script of mine. It had done well :frowning:

Usage: Attach it to a cube, set the scale of the cube to (1,1,5), make it like a pillar. Try to press and hold “m” key to see the pillar raised :slight_smile:

205006–7553–$mypillar_952.js (1.27 KB)

You need to remove these two lines:-

plane.AddComponent(MeshCollider); 
plane.GetComponent(MeshCollider).convex = true;

…and add a BoxCollider instead. Is there any particular reason why you are creating this object in a script rather than just using the editor?