How to assign the "Mesh" in "Mesh Collider&qu

Hi all, thanks for any help-

I’ve looked up several people apparently being able to make this work, but no matter what I try it’s just FAIL.

I’m just looking to assign a specific mesh to the “MeshCollider” of my Game Object, but can not get it to work, no matter how many methods I try.

here is an excerpt of the code I’m using:

	var playerLevel = 0;
	var playerCurrentMesh : MeshRenderer;
	var playerCurrentCollider : Mesh;
	var playerMeshes : MeshRenderer[];
	var playerColliders : MeshRenderer[];

function Awake ()
{
	playerCurrentMesh = Instantiate(playerMeshes[playerLevel], gameObject.transform.position, gameObject.transform.rotation);
	playerCurrentMesh.transform.parent = transform;
	playerCurrentCollider = playerColliders[playerLevel].GetComponent(Mesh);
	gameObject.GetComponent(MeshCollider).sharedMesh = playerCurrentCollider;
	gameObject.GetComponent(MeshCollider).collider.isTrigger = true;
	
}

I’m very much a noob at programming, so if the above code is ugly, feel free to tell me ways I could fix it up as well :slight_smile:

Most importantly, I’m just looking to fix this issue!!

I get no errors or anything- it simply does NOT place that mesh in there!

Thanks all!

How are you determining that the MeshCollider hasn’t been added? If you are finding that objects entering the trigger don’t fire the OnTriggerEnter event, then there could be another reason for this.

One or other of the colliding objects must have a rigidbody component (this can be set to isKinematic, if you don’t want physical behaviour on that object). Also, generally, two MeshColliders don’t register a collision (or trigger event) unless one of them is set as convex.

hey, thanks for the response-

I am determining it by watching the Inspector panel, while having the object selected during game testing.

One of the objects definitely has a rigidbody, that much works fine, so it is definitely an issue with something else, unfortunately.

STILL can’t get around this issue. Hope someone can help me out!

Thanks!

What does the inspector say for the value of the mesh property after you’ve assigned sharedMesh?

Is the object that is supposed to collide with the created MeshCollider also a MeshCollider? If so, it will need to be marked as convex for the collision to be detected.

the value stays “none”, no change…

at this point I’m not so worried about the colliding objects, more into simply getting this collision mesh to show up. All my triggers/etc work fine, I’ve dealt with those previously.

arg!

thanks again!