Unity Optimisation Basics Part 1
来源:互联网 发布:python就业班视频 编辑:程序博客网 时间:2024/05/29 10:14
转自:http://stevehalliwell.com/unity-optimisation-basics-part-1/
I recently decided to run the unity profiler over JSD and see what could be improved, this is just a quick review of my findings.
Searching is bad.
查找效率低
I already avoid all Find and GetComponents when ever I can so there weren’t many of them to find. I don’t recall if it was AltDevBlog or the Unity Blog itself or in a Unite or Learn video but it doesn’t matter. GameObject.Find*, Object.Find* and GetComponent are all expensive and wherever it was, explained that its simply because unity does a linear search through the collection to find them. Makes sense in a way, even if they were O(log n) it would still be expensive to do them all the time and would require the internal storage to be not cache sensitive or lazy.
Collision layers, use them.
假如子弹和子弹之间不发生碰撞,将子弹和敌人位于不同的layer,效率会提高
JSD has a lot of trigger rigidbodies, I had set it up so bullets didn’t overlap with withselves and never gave it another thought, until I saw 126 calls to OnTriggerEnter in 1 frame. Lots of bullets overlapping enemies however. It did a few checks and threw it away. Changing bullets to be in either a only collides with player layer and vice versa (an only collides with enemies layer) reduced this down to much more acceptable levels. This also drastically reduced the number of contact pairs the phys engine has to create and maintain which greatly lowered the overall and consistly high amount of cpu time spent in the physics engine.
yield rarely
yield即使没有取得结果,他也会造成10%额外的负担
The bullet spawners had a yield still in them from an earlier debugging attempt to prevent infinite loops during testing, this seemingly harmless line
was causing an additional 10% overhead on that function call. This again is not surprising, if you haven’t have a look at http://www.altdev.co/2011/07/07/unity3d-coroutines-in-detail/ its not an inconsiderable amount of work to make that co-routine happen, even if the line with the yield never gets hit.
Pools are not a silver bullet
我用对象池避免移动设备强制销毁内存。游戏过程中,你应该像避免瘟疫一样避免内存分配。我发现无论什么时候去激活对象ctiveInHierarchy = true都是十分昂贵的。
I use object pools (of my own creation) to avoid trashing memory which is mandatory on mobile if not everywhere. You should avoid allocs during gameplay like the plague. I found however that activating objects (.activeInHierarchy = true) is still quite expensive.
Surprisingly, splines are not using much at all, neither is overall rendering.
- Unity Optimisation Basics Part 1
- Unity Optimisation Basics Part 2
- Unity Optimisation Basics Part 3
- DB2 Backup Basics - Part 1-3
- Java Basics Part 1/20 - Overview
- [Dividend] Basics -- Part I
- Groovy Tutorial for Java Developers – Part 1: The Basics
- Untangling Apache Hadoop YARN, Part 1: Cluster and YARN Basics
- CUDA Programming Basics Part I
- CUDA Programming Basics Part II
- unity NUGUI tutorial the basics
- Unity iOS 基础 Unity iOS Basics
- Print.PrintBookmark with del.icio.usXML Basics for Java Developers, Part 1
- How to secure an Ubuntu 12.04 LTS server - Part 1 The Basics
- Java Basics Part 2/20 - Environment Setup
- Java Basics Part 3/20 - Basic Syntax
- Java Basics Part 4/20 - Object & Classes
- Java Basics Part 5/20 - Basic Datatypes
- scala入门-08 apply方法和单例对象的使用
- URL和URI
- IOS SDK百度地图不能正常显示,只显示网格
- C++ Virtual详解
- hive之窗口函数理解与实践
- Unity Optimisation Basics Part 1
- Xcode5修改APP的名称与包名
- java中web.xml配置文件
- Eclipse 项目出现红 x
- 奇偶个数
- IDEA 改变编码方式
- Hibernate的优缺点
- php 之apache rewrite伪静态的简单配置和使用
- 64位ARM在Android系统中适配32位静态库