Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Performance on an android game - procedurally generate map vs generate everything in the beginning?

Discussion in 'Scripting' started by xred13, Jan 3, 2019.

  1. xred13

    xred13

    Joined:
    Jul 14, 2018
    Posts:
    74
    Hi, so I don't really have much knowledge about this, so I am here asking... i want to make a racing game for android, is it better to have the terrain procedurally generate as the player goes or generate the whole race in the beginning? The race's would have a beginning and an end.

    Is the performance bad if the whole terrain in instantiated in the beginning or can i optimize it well? How would I?
     
    Last edited: Jan 3, 2019
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    That question's answer is dependent on everything from the total size/length of the map, density of detail of the geometry, the repetitiveness of the data, the portion of the map that would be "visible" and in the camera frustrum at one time, etc., among other factors.

    Generally the rule of thumb for mobile is to do as little work as possible during actual gameplay. Either do it all in the editor as a scene, or else do it all at scene load time. Sometimes you can get away with spawning and destroying on the fly, but there will always be some lower-performance device upon which your game will stutter.

    As a mobile game engineer, your job is to empirically devise a solution to implement your game idea that runs okay on enough platforms that you're happy. Use the profiler window in Unity to get additional insight into where your code might be taking too much time.

    Good luck!
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    What do you feel like you have to spare, CPU or RAM?

    Spawning everything on load will take up more RAM, doing so during gameplay will use up valuable CPU time.
     
    Joe-Censored likes this.
  4. xred13

    xred13

    Joined:
    Jul 14, 2018
    Posts:
    74
    I am mostly afraid of the fps while playing instead of the performance issues while actually spawning stuff
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Unfortunately, it's not that "white and black". Some devices (both phones and tablets) have VERY limiting ram.
    Some older ones got 512MB, while other got 1GB (e.g. old generations of IPhones).
    Some of the crappy branded chineese phones may have the same amount of ram as well.
    But then again, older phones will have an issue with loading lots of stuff.

    Afaik, default terrain eats quite some chunk of the ram, so you might want to do custom geometry via 3d tools.

    Your best bet, I think, is to test on the actual device and pick your "target" audience.
    Also, moving map generation execution order from one point in time to another shouldn't be that of an issue.

    And again, it depends on how big your map size should be.

    If it's a racing game - simply premade tracks in editor, and load them in-game after user selects the track. (Or by any other logic).
    If it's something else - well that require more details.

    TL;DR: Both approaches are viable if done correctly and both have their cons / pros.
    So I'd say - figure out design first, then do optimizations.