Search Unity

Profiling : Physics2D.Simulate

Discussion in 'Scripting' started by alimrafeek, Nov 8, 2020.

  1. alimrafeek

    alimrafeek

    Joined:
    May 22, 2018
    Posts:
    14
    Hi

    Trying to develop a 2d mobile game. I've been looking to improve the fps of the game on low end devices.
    I am trying to study and understand the profiler in unity.



    PostLateUpdate.FinishFrameRendereing and FixedUpdate.Physics2DFixedUpdate are taking up lot of processing power.

    I read that setting Physics2D.autosimulation to off and calling Physics2D.Simulate(Time.deltaTime) from Update solved the problem. But Physics2D.autosimulation is deprecated. Unity suggests to use Physics2D.simulationMode instead. But their is no proper documentation to how to do this.

    Any Help on this matter is appreciated. Also is there another way to solve this problem?

    Thanks!
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,991
    What do you mean by there's no proper documentation? There's Physics2D.simulationMode and it directly has a cross reference to the actual SimulationMode2D enum which essentially explains the 3 different values you can choose.

    However I'm not sure what you expect to improve when you manually simulate the physics loop. Keep in mind that Physics2D.Simulate does only advance the physics engine. It does not call your FixedUpdate methods if you have any code inside FixedUpdate. If your code in FixedUpdate is too heavy that's where you should start investigating.

    Maybe try a doing a deep profile to see how the time breaks down. We don't see your image because you used an external hoster and you didn't use an actual image link but a link to a website. Your fixedupdate and physics simulate only takes 3.8 milli seconds. So the physics part is small compared to the rest. It's only about 2% of your total frame time. So you want to look into that 89% what's going on there.
     
  3. sudunity12

    sudunity12

    Joined:
    Feb 10, 2018
    Posts:
    14
    To use Physics2D.simulationMode,
    Physics2D.simulationMode = SimulationMode.FixedUpdate;
    you can use SimulationMode.Update instade FixedUpdate