1
\$\begingroup\$

I am looking to push the 2D physics in Unity to the extent where when so much is going on that there becomes noticeable lag in a game. This is for testing purposes, so that when so much is going on that a button can be pressed to reduce the amount of physics objects on screen then see what affect that has. So in my small 2D demo I have placed alot of barrels on the map, all of which have physics on them, player bumps into them and they move. I have went to the extent of placing alot of them on the map (864 to be exact), bumping into them I still don't see any effect on the gameplay. Other things I have tried, besides adding alot in, is increasing the mass of the barrels, changing their linear and angluar drag and making them bouncy.

Is there anything I can do besides adding alot more in? Thanks!

\$\endgroup\$
6
  • \$\begingroup\$ Add RigidBodies to them. \$\endgroup\$
    – jgallant
    Jun 18, 2015 at 12:32
  • \$\begingroup\$ Rigidbody2d is already added to all of them \$\endgroup\$
    – CH99
    Jun 18, 2015 at 12:40
  • \$\begingroup\$ The physics is just one aspect of CPU usage in a game. Don't push the game to the limits with physics, and then throw more on top that will put you over the edge. \$\endgroup\$
    – Logarr
    Jun 18, 2015 at 14:35
  • \$\begingroup\$ @Logarr What other aspects of CPU usage are there? \$\endgroup\$
    – CH99
    Jun 18, 2015 at 14:39
  • 2
    \$\begingroup\$ If you're repeatedly spawning a common object and removing it, I'd recommend using an object pool. Making the garbage collector work too often can be a major cause of hiccups that don't appear when you're just testing for a specific purpose, but hinder actual gameplay seriously. \$\endgroup\$ Jun 18, 2015 at 16:09

2 Answers 2

2
\$\begingroup\$

I would suggest procedurally spawning the object constantly, and adding mesh colliders. Mesh colliders are very cpu intensive, and if you have a script that continuously creates these barrels, it will keep doing so until you kill unity. You can also track your gameplay statistics by clicking on the stats button up the top of your game window.

\$\endgroup\$
3
  • \$\begingroup\$ Haha, you beat me by a few seconds :) \$\endgroup\$
    – Marc
    Jun 18, 2015 at 12:49
  • \$\begingroup\$ Yeah so I did. I was sitting on it for a few minutes too, getting links and such. Good answer. \$\endgroup\$ Jun 18, 2015 at 12:50
  • \$\begingroup\$ Thanks for the reply guys, figured I wouldnt have any other options left, will do the mesh colliders, ty! \$\endgroup\$
    – CH99
    Jun 18, 2015 at 13:10
2
\$\begingroup\$

I think the amount of entities is the best to test that and to keep things simple just multiply them. Simply add a script to your barrel prefab which will wait 1 second after start and then spawn two more entities of the same object. Add some force to push them away.

That way you only have to place one instance on your screen, start your game and wait a bit. The multiply will come into effect pretty soon as each object will spawn two new ones.

Maybe add a counter as well so you can see how many are on the screen at the moment.

Then all you have to do is to sit and wait until your game becomes sluggish or crashes. Shouldn't take forever... :)

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .