Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Physics2D SolveDiscreteIsland performance bottleneck

Discussion in 'Physics' started by Skullek, May 13, 2020.

  1. Skullek

    Skullek

    Joined:
    Mar 16, 2018
    Posts:
    22
    I have a huge problem with the performance of my system.

    I have a system that spawns a particle that emerges from the far Z axis and is blurred. Slowly moves to point 0 (on Z axis) and animates to sharp image. Then the particle floats around the map using fixedupdate.

    There are approx. 300 max 400 particles on the map at any time, never more.

    With that system turned off my game works in 50-60 fps. With that system 25-30.
    How can I improve this. Physics2D.Simulate on development build with profiler ON is taking 30ms

    The screenshots are from the profiler on the android phone.


    Single particle



    Grow coroutine -


    FixedUpdate
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,740
    The 2D solver is solving contacts so if it's taking a long time, it's because there are a lot of contacts to solve and potentially you've got a lot of solver iterations set.

    The particle system has nothing whatsoever to do with physics so I'm not sure I following the reference. Are you using Dynamic rigidbodies as particles? Why not use the particle system? If you have these "particles" (colliders/rigidbodies) overlapping then each would create a contact with each other if they interact.

    Using Rigidbodies as particles is a pretty brute force thing to do if that is indeed what you're doing, especially on a lower power device.
     
    Skullek likes this.
  3. Skullek

    Skullek

    Joined:
    Mar 16, 2018
    Posts:
    22
    I didn't know how to get this specific behavior in built-in 'particle system'

    I need objects that will slowly sharpen and appear from far away Z. They don't react with any other objects until they reach point 0 on Z axis.

    I have quite specific requirements for working with other objects when they are at 0.
    They work with triggers on some objects, on colliders with some, they don't collide with some and they connect with some.

    But they usually don't even overlap with anything
     
    Last edited: May 13, 2020
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,740
    I would certainly investigate using the particle system as using Dynamic rigidbodies like this isn't going to scale very well at all. If you don't want a Rigidbody2D to be part of the simulation (no iteraction) for certainly periods then use Rigidbody2D.simulated where you can as this is the "lightest" way to have it ignored completely by the simulation until you need it.

    As a side-note, you should not be manipulating the Transform when using a Rigidbody2D as that is its job but it sounds like you have other problems right now.
     
  5. Skullek

    Skullek

    Joined:
    Mar 16, 2018
    Posts:
    22
    Am I able to check the state of each particle (in built-in system), whether it has already arrived at point 0 on Z axis, check collisions and triggers + effectors (some of particles has some point effectors 2d) and at the same time animate each separate particle from texturesheet?

    I think I can somehow solve this overhead problem, it's only 300 objects, not 2000.
    I just forgot about some detail, tick, one line in script. I can feel it: D
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,740
    I'm not a particle dev but no, particles don't interact with effectors. They can have simple collision only.
     
  7. Skullek

    Skullek

    Joined:
    Mar 16, 2018
    Posts:
    22
    Please help, anyone? <3