ME FIRST GAMES
Menu

games for me and you

Coding Tips - Unity Performance

6/26/2020

0 Comments

 
Picture
Here are some super basic tips to increase your game's performance in Unity
📌 Only run code when things change. Instead of constantly polling and checking a state inside Update, try using Events and Actions to trigger code when something changes.
📌 If polling is required, then try only running your code every N frames or after a delay. Your AI code probably does not need to fire every frame.
📌 Move code out of loops when they can be run once, before, or after.
📌 Cache references and values instead of calculating them every time. GetComponent is included.
📌 Pool objects instead of Instantiating everything. Keep GameObjects in a list and when they are no longer needed, disable them. Enable them later as needed.
📌 Never use SendMessage and Camera.main. They are slow.
📌 Do not use FindObjectOfType. Instead, serialize a reference and link it in the Editor. Alternatively, you can create a singleton and use the reference directly.
📌 Avoid Vector3.Distance and Vector2.Magnitude because they use square root calculations. When possible, use Vector3.sqrMagnitude.
📌 Manually call System.GC.Collect() during loading screens or scene transitions.
📌 If you're getting large CPU spikes from garbage collection, then try incremental garbage collection.
📌 Disable/Enable MeshRenderer's using MeshRenderers.enabled. There is overhead activating and deactivating GameObject's with SetActive.
📌 Avoid calling DestroyImmediate.
📌 Store settings inside of ScriptableObjects instead of Prefabs. This avoids redundant variables allocated for prefabs using the same settings. 

0 Comments



Leave a Reply.

    Picture
    Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
    GAMES HERE

    Red Matter

    Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.

    Archives

    April 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2019
    March 2019
    December 2018
    April 2018

    Categories

    All

    RSS Feed

Copyright (c) 2020 Me First LLC
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments