Search Unity

How many active rigidbody can an iPhone 8 handle ?

Discussion in 'Physics' started by Aladine, Jan 7, 2022.

  1. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    Hi,
    I am working on a mobile game where its core gameplay includes a bunch of rigidbody (can exceed 100) walk around an environment where they push each other and get pushed by other colliders too, and I have a couple of questions so I can adjust my expectations and how to handle the optimization part:

    First of all, is this a good idea ? the physics is not used for any realistic simulation, it's basically used to do the following:
    • Make character move from point A to point B
    • character can push objects with lower pass and get blocked by object with larger mass
    • there are dynamic walls and "doors" that moves across the level and the push the characters accordingly
    • all of the above happens for a minimum of 40 rigidbodies at once, and it can reach ~200 sometimes
    So how bad is this for a mobile game ? we are aiming for 60fps and decent battery life on iPhone 8 and higher, is this possible ? if not, do you recommend an alternative solution ?


    If this is indeed possible, what would be the best way to optimize it ? because currently we have a lot of FPS spikes, and the phone get hot really quickly, which is not good at all.

    I am using unity 2019.LTS, and also considering using DOTS but am not sure if its the right call at the moment.

    Thanks!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,478
    A Rigidbody isn't a unit of performance. What happens in the simulation is what costs i.e. the number of contacts being solved and other stuff. Contacts and them being solved is often a dominant part of the simulations step and not integration of bodies.

    The only way to answer questions like this is to direct you to the profiler, your device and a simple test project you create to answer your own question. Make a simple project that roughly approximates what you want to do and test it.

    If you have "FPS spikes" then I'd say dig in to the profiler and find out what's causing them. If there's something specific then that's an optimization question that might be possible to answer. Spikes often relate to suddenly adding things to the simulation and/or creating things that overlap for one simulation step because they are not instantiated in the position they should start at due to Transforms being changed and not the bodies directly. All sorts of things.
     
    Aladine likes this.
  3. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    Does this helps ?



    And yes I do have FPS spikes, and its almost always related to creating brand new rigidbodies at once, the gameplay rely on a "multiplier mechanics" where a singe rigidbody can go through a door and get multiplied by 5, so if 10 walks through that door, they immediately become 50.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,478
    Help how? An absolute number doesn't give you an indication of how it performs on a device or at least I don't have some table to compare it too. I mean the numbers don't look super high but obviously that depends on the device. Assuming this is the peak/spike you're referring to.

    As I said, if you're getting spikes, make sure you're creating the things in the correct location and not causing lots of contacts for a single simulation step (total guess). If you get a spike in contacts, work on that not being the case. If it's unavoidable (for whatever reason) then that's your answer, your device cannot handle it. Honestly, I cannot debug it on a forum for you with a few pictures. The profiler will tell you what specific part is taking the time.

    Seeing 18.9ms tells me it's running at no more than 52fps. It doesn't enable me to tell you anything unfortunately. I'm also not a 3D physics dev but I believe "Physics.Processing" is pretty much the whole simulation step so you'd need to dig in further than that.
     
    Aladine likes this.
  5. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    I see, thanks, will dig further then :)