Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

2D Physics optimisation - TransformChangedDispatch

Discussion in 'Physics' started by fjack, May 5, 2019.

  1. fjack

    fjack

    Joined:
    May 5, 2019
    Posts:
    4
    Hi,

    I have a very simple 2D physics based game, with one RigidBody2D and a number of fixed colliders. As part of an attempt to procedurally generate levels for the game, I am experimenting with manually simulating physics in order to test whether a given level is solvable / playable. Basically, for a range of inputs, I simulate physics forward (using Physics2D.Simulate(Time.fixedDeltaTime) in a loop), test if a win condition is met, then reset the position, velocity, etc of the rigidbody and try the next input.

    This works quite well. The only issue I'm having is performance: obviously the faster I can make this loop run, the faster I can test levels / the deeper I can go (in terms of recursively testing actions).

    The thing that appears to be slowing the Physics2D.Simulate call down is TransformChangedDispatch . Does anyone know what this is / if I can avoid it? I have experimented with setting Physics2D.autoSyncTransforms = false, and manually / never calling SyncTransforms(), but this doesn't seem to affect the performance of those calls. Nowhere in the code within the physics loop do I ever set any property of any transform directly - I am only applying forces to the single rigidbody, and modifying its velocity (for a custom drag calculation). I am happy to go to some extra efforts to optimise this loop - any pointers or ideas would be great. I have attached a screenshot of the Unity profiler on one of the Physics2D.Simulate() calls.
    Screenshot from 2019-05-04 21-18-45.png
    Thanks
    J
     
  2. fjack

    fjack

    Joined:
    May 5, 2019
    Posts:
    4
    Bump