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. Dismiss Notice

Question Does size matter

Discussion in 'Scripting' started by kader1081, Jun 22, 2023.

  1. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    365
    Hi, I am trying to make a 2d voxel game and i am curious about does tiles or characters size matter for performence. I am getting very nice fps about 50 k tile so ı dont know if it affects the performance by the way tiles have 2 components sprite renderer and box collider2D.I set false tiles that are not visible and create or set true tiles that became visible.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    50k tiles is around 225x225 tiles. That's not a very big map. ;)

    What I found during my extensive research (see my signature) is that each tile in a Unity 2D Tilemap is a game object. That means with 50k tiles you will notice that the scene size has probably already grown close to a hundred megabytes. In my tests I was able to get a scene the size of nearly a gigabyte just by drawing one huge rectangle that had close to 500k tiles if I recall correctly.

    If you don't use Unity Tilemap you still seem to be working with Game Objects so you'll run into the same issue. If you do have 50k game objects in your scene, check your scene size on disk. ;)

    Fortunately, as long as you don't render too many tiles on the screen the performance does not suffer. Just don't try to zoom out to show all tiles. And of course the memory usage remains static, so it's going to be pretty high.

    The size of a tile - if you mean dimension in pixels ie 64x64 - does not matter for performance. It matters only how many tiles the camera draws, whether it's 100 or 1,000.
     
    kader1081 likes this.
  3. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    365
    Actually they are not tiles gameobjects. I am making a kingdom new land like game they will act as ores dirts etc
     
  4. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    365
    I looked at game file but it is about 250 mb and it is unity files itself not scene.Folder that has scene is about 350kb
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    The .unity file is the scene. The folder you see is just extra data, typically lighting info.

    No doubt, with 250 MB scene size you must have tens of thousands of game objects in the scene hierarchy. ;)
     
    kader1081 likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Size matters is different from a $4000 ultra high-end gaming rig and a $50 Android tablet from Costco.

    You may choose to ask "is this gonna be fast enough?" as much as you like, but you won't ever answer it except perhaps by luck.

    And then when you change to a different piece of hardware, your answers will become invalid.

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
     
    Yoreki likes this.
  7. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    What matters is how many tiles are on screen. Not how many tiles you have.
    I don't know the situation but let's say you have handled occlusion culling, or the equivalent of; it only depends how many you are looking at. So size matters. Larger tiles may render less of them on screen. But that may also depend on camera position as well.

    There's nothing wrong with having scale be 100, but if there was a way to reduce it to 1, then you can't go wrong.

    Many objects is always a problem, so combining tiles into groups and combining them will see improvements as well.
     
    Yoreki likes this.