Hello Guest

Author Topic: How do I get the polygon collider to update when I change animation?  (Read 7747 times)

Bennett

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
I'm generating prefab animated sprites at runTime, and selecting an animation after instantiating them. But they all default to the collider set for frame 0. How can I get it to update the colliders as the frames change?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #1 on: April 15, 2012, 06:31:28 pm »
You need to set up the colliders on all the frames. If you have 1.60 (if you don't, you should upgrade, the editor is very much improved), simply shift select all your sprites, change the collider type, click Apply (to apply the change to all sprites) and Commit your changes.

Bennett

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #2 on: April 15, 2012, 06:40:22 pm »
I had already done that. The issue is that it doesn't update the collider at runtime.

And now I have an even worse issue, which is that I can't change the animation at all at runtime :-/

Not sure if it's a bug - I don't think I changed anything!

I'm calling it as follows (My animations are named "0", "1", "2", etc., and all the animated sprites are stored in an array called "_sprites"):
Code: [Select]
for (var i : int = 0;i < _sprites.length; i++) {
     var anim:int = Random.Range(0,4);
     _sprites[i].GetComponent(tk2dAnimatedSprite).Play( anim.ToString() );
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #3 on: April 15, 2012, 06:43:45 pm »
Would it be possible to send me a test case? If so, please use support at unikronsoftware dot com. Otherwise, I will need a bit more info on what's going on and how things are set up.

Bennett

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #4 on: April 15, 2012, 07:33:05 pm »
I got it working by making a new SpriteAnimation object. I guess the old one got corrupted.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #5 on: April 15, 2012, 08:12:29 pm »
If this ever happens again, could you save a test case out for me please? Those files should never get corrupted (unless metadata is lost, but you'd have a lot more to worry about than just this if that happened)

Bennett

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #6 on: April 15, 2012, 08:23:30 pm »
Sure.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #7 on: April 16, 2012, 10:37:14 am »
Sorry, I misread this question altogether. The polygon collider can't update in an animation. Doing so will require recreating the MeshCollider component every frame, which is really really slow.

Bennett

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #8 on: April 16, 2012, 10:45:11 am »
Ok. But in the file I sent you, I'm also finding it impossible to change between animations using script.

I'm calling myTransform.GetComponent(tk2dAnimatedSprite).Play("animationName") but nothing happens. What am I doing wrong?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get the polygon collider to update when I change animation?
« Reply #9 on: April 16, 2012, 11:00:20 am »
I'll look at that shortly, and get in touch by mail if I need further info