Hello Guest

Author Topic: updating coliders , performance  (Read 7165 times)

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
updating coliders , performance
« on: March 07, 2015, 08:24:41 pm »
i have read somewhere that if you move a collider with no rigidbody or if you move a collider with rigid body but you move it by changing its transform not by rigidbody functions you are not doing it right cause the physics engine has to recalculate the position of all colliders

if this is true, i guess that to use tk2d frame colliders is not very efficient cause as the collider has to be regenerated each frame it will cause the physics engine to recalculate everything, right?

don't get me wrong, the frame colliders is an awesome thing, but i want to know how inefficient is it for the psx engine so i can think an alternative method... or not

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: updating coliders , performance
« Reply #1 on: March 09, 2015, 11:55:45 pm »
Quote
if this is true, i guess that to use tk2d frame colliders is not very efficient cause as the collider has to be regenerated each frame it will cause the physics engine to recalculate everything, right?
Yes, so you should have a kinematic rigidbody on any colliders that move in any way. But you'd have that anyway if you were moving it, right?

Quote
i have read somewhere that if you move a collider with no rigidbody or if you move a collider with rigid body but you move it by changing its transform not by rigidbody functions you are not doing it right cause the physics engine has to recalculate the position of all colliders
No that isn't correct.


drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: updating coliders , performance
« Reply #2 on: March 10, 2015, 01:02:07 am »
but i wonder, is it correct to mod/recreate the collider of a rigidbody?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: updating coliders , performance
« Reply #3 on: March 10, 2015, 10:42:33 am »
Yes its fine. As with most things its depends on what you're using it for and where. If you're doing this on all objects in the scene thats bad, but if its just for one object that should be fine.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: updating coliders , performance
« Reply #4 on: March 10, 2015, 01:29:31 pm »
Actually, you do indeed get some spikes when moving colliders via transform instead of rigidbody.MovePosition(). At least from my profile tests. There's a physics "UpdateTransform" (or something like that, I don't recall exactly) call that is expensive (relatively speaking) that doesn't happen if you move via rigidbody. This is regardless if the collider is a trigger or not.

That said, you probably wouldn't notice anything unless you had a ton at once.

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: updating coliders , performance
« Reply #5 on: March 11, 2015, 09:23:30 pm »
Actually, you do indeed get some spikes when moving colliders via transform instead of rigidbody.MovePosition(). At least from my profile tests. There's a physics "UpdateTransform" (or something like that, I don't recall exactly) call that is expensive (relatively speaking) that doesn't happen if you move via rigidbody. This is regardless if the collider is a trigger or not.

That said, you probably wouldn't notice anything unless you had a ton at once.

thanks, i have read a couple of forums and articles about this, since then i changed my code and now uses rigidbody2D.MovePosition i even made my tests with a loop of 30.000 iterations and saw the differences , thats all ok for the rigid body in the main GO, but in my hero i have different colliders as children and depending he is  walking or crouch or he is KO i need to change shape or at least move the children colliders

even if it is not noticeable cause very few colliders to be altered, i am worried about the garbage collection , i am rewriting my code to avoid the GC collect call that happens sometimes and in my game, for unknown reason is making a huge spike.

im not expert so i don't know how to read the profiler information exactly but seems that the garbage is generated cause 59 calls that change collider transform in my player script ...? is that correct?

i need to clean this as i plan to use the same script for other 20 or 30 characters in the game all running at once...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: updating coliders , performance
« Reply #6 on: March 12, 2015, 11:12:14 am »
There is no garbage generated by that, GC Alloc = 0.
You should deep profile to get more info.

Your game.update script is generating a fair bit of garbage though.