Search Unity

[SOLVED] At the beginning of unity physics simulate has low performance

Discussion in 'Physics for ECS' started by Izumeow, Nov 27, 2019.

  1. Izumeow

    Izumeow

    Joined:
    Apr 3, 2019
    Posts:
    2
    Hello! I use DOTS unity physics in my new project.

    There are 140 Entity collide at the same time, but at the beginning of unity physics simulate has low performance. like this snapshot :
    upload_2019-11-27_11-10-59.png

    when the physics runs a while:
    upload_2019-11-27_11-13-36.png

    this is my code on creating objects :

    Code (CSharp):
    1. void AddEntity(GameObject LevelReference)
    2. {
    3.     EntityManager manager = MainSystem.Instance.EntityManager;
    4.     Entity Reference = MainSystem.Instance.SystemData.PoolGameObjects.E_Object;
    5.  
    6.     NativeArray<Entity> E_Objects= new NativeArray<Entity>(LevelReference.transform.childCount, Allocator.TempJob);
    7.     BlobAssetReference<Collider> sourceCollider = manager.GetComponentData<PhysicsCollider>(Reference).Value;
    8.     manager.Instantiate(Reference, E_Objects);
    9.  
    10.     for (int i = 0; i < E_Objects.Length; i++)
    11.     {
    12.     manager.SetComponentData(E_Objects[i], new PhysicsCollider { Value = sourceCollider });
    13.     manager.SetComponentData(E_Objects[i], new Translation { Value = LevelReference.transform.GetChild(i).transform.position });
    14.     }
    15.  
    16.     E_Objects.Dispose();
    17. }
    I wonder how to optimize this situation, Like deal these job(Process Body Pair Job, Build Contact Jacobians Job)in advance, or reduce processing time on these job.

    thanks! :)

    update:

    I do some testing :
    • When created entity , pause and wait for a while will let FPS drops to normal immediately.

    update(12/3):

    Thanks for tertle's answer ! :)



    If check this option, I have to compiled to continue the game, but in that way, application will stop for a while, I don't want that in the final version.

    So I try to build game and test performance -- burst are building in very few milliseconds! every thing is fine now ;)

    But when I test game, it still have times to compile burst. If you know how to solve this problem, please tell me, thank you!
     
    Last edited: Dec 3, 2019
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Do you have asynchronous burst compiling on? The burst jobs probably haven't compiled yet. What does it look like if you enable synchronous (or in a build.)
     
  3. Izumeow

    Izumeow

    Joined:
    Apr 3, 2019
    Posts:
    2
    !!!!!!!!:eek: you are right :eek: !!!!!!
    But before burst jobs compiled, Unity will become unresponsive.
    Can I compiled in advance?