Hello Guest

Author Topic: Mesh collider not being created.  (Read 4990 times)

spinner

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Mesh collider not being created.
« on: September 15, 2013, 04:11:27 pm »
Hello,

I have a sprite which I added a polygon type collision.
Creating the sprite through unity editor, seems to be working ok. However, if I instantiate the game object through code:
Code: [Select]
GameObject go = new GameObject();
tk2dSprite sprite = go.AddComponent<tk2dSprite>();
sprite.SetSprite(spriteCollection, spriteName);
Then the meshcollider is not being created.

Weird thing that other sprites that use box trimmed or box custom works normally even when instantiated directly on code (using the same template as above.

Is that a bug? or Am I doing something wrong?

Thank you.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mesh collider not being created.
« Reply #1 on: September 15, 2013, 09:56:10 pm »
Its not a bug as much as its not meant to do that at runtime. Creating mesh colliders is really really expensive at runtime and the code doesn't to avoid situations where you animate it by accident. You can enable it by changing a few lines of code, but please do be aware of the implications.

spinner

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Mesh collider not being created.
« Reply #2 on: September 18, 2013, 01:59:42 am »
Right, I can understand that.
But actually, I´m using a mesh collider just because I can't use a rotated box collider.
Is there another way to workaround that?

thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mesh collider not being created.
« Reply #3 on: September 18, 2013, 11:23:10 am »
Kinda - 2D Toolkit 2.3 will have support for custom arbitrary colliders with rotation support. They have to be created as a child in Unity hiearchy, which is why it can't be done with the current system.

Alternatively, you can set the Collider Type to UserDefined, and you can set up anything you like in the inspector after you've created your sprite.