Some kinda Basic Questions about Optimization.

Hello fine folks! Kellion here. So… I’m developing a mobile game and being extremely new to optimization and unity in general, I do have some questions about how to waste the least possible performance. The language I always use is C#. Game in question is a SCHMUP with lots of simple enemies and bullets.

Buckle up, as there are a few of em’

-Continuously update a transform in the Update() function? Or do a “if X = Y then Update transform”?

-Can this line be optimised? (It’s used to make an object move continuously towards an angle specified by its Z euler.angle, it’s used by the majority of bullets in the game) - "transform.localPosition += transform.rotation * Quaternion.Euler(Direction, 0, 0) * transform.forward * Speed;"

-(Not about Optimization but might as well get it answered right here) Are invokes affected by Time.deltatime?

-Use multiple objects that each have a sprite component attached? or a single object but with some exotic script that has multiple sprites somehow?

-Do empty objects weight significantly?(With just a transform attached, nothing else)

-Use an Invoke.repeating to check for x=y questions? Or just use the x=y in the update function.

-Use x += 1* time.deltatime in the update function to simulate a clock? Or something else? Or an invoke?

-Using if x=y instead of always changing a basic number in each Update() call(like X = 2 or something along those lines)

-Use a single large script? Or multiple smaller scripts?

-Do scripts only containing a Start() and some variables weight significantly while the game is running?

-Are Ints faster than floats in CPU? Or just on memory?

-Use fixed framerate? Or Time.deltatime?

-Change the transform.position via New Vector3 or use something else?

-Is 2D circle collision faster than 2D square collision like it is with their 3D cousins?

These are the questions that most bugged me lately. I apologise if some questions are so similar that they might be repeats, I’m in newbie land so It’s going to be like this, but for my game to be able to run properly with the high amount of objects in the scene, each of those objects better be fast.

Thanks for reading :smiley:

I 'm not gonna answer all questions but here are some:

  • Use events as much as possible and
    use instead of checking everything in
    Update. Doing stuff in Update is
    justified when it needs to alter
    every frame (movement). A simple if
    statement in Update is not that much
    of an impact but keep it simple
  • Use fixed framerate
  • ints are faster than floats
  • Code in start only happens
    once so it won’t have any affect on
    the game once it is executed.
  • Large or small scripts is only relevant for
    the programmer. Use many small
    scripts for better maintenace purpose
  • Empty objects have almost no effect on performance
  • Use the editor log in the console window (upright corner) to see which elements take up the most memory after you made a build. Mobile devices work best on a low memory footprint.
  • Use the profiler to see how the game performs

Succes