A Software Engineer’s Guide to Unity and AR/VR Development – Part 1
I hate to be that guy on HN but this article set me off as a Unity VR developer. I understand this is an introduction for people coming from a web development or other more traditional software engineering background, and the code is purely demonstrative, but it's full of Unity performance anti-patterns.  Specifically...<p>1) Resource.Load and GameObject.Instantiate during a runtime loop.  Both of these are very expensive and will generate a ton of garbage.<p>2) Constantly Instantiating and Destroying GameObjects during runtime.  This will create a ton of garbage on top of the expense of the Instantiate.  The solution to this should be an object pool (<a href="http://catlikecoding.com/unity/tutorials/object-pools/" rel="nofollow">http://catlikecoding.com/unity/tutorials/object-pools/</a>
).  Realistically this is probably outside of the scope of this blog post, but maybe the author should have avoided Instantiate in an introductory example.<p>3) GameObject.Find to locate a fixed game object in the scene.  This should be replaced with an object reference (references can be connected in the editor), or if that doesn't work for whatever reason use Find once in Start or Awake and store a reference to the object are a member variable.  Unity recommends to not use it every frame in it's documentation (<a href="https://docs.unity3d.com/ScriptReference/GameObject.Find.html" rel="nofollow">https://docs.unity3d.com/ScriptReference/GameObject.Find.htm...</a>)<p>4) Debug.Log can be useful in a pinch, but doing it in Update or other frequently called method can cause performance problems, also printf debugging has never been great.  Visual Studio debugger support is really good in Unity, use that.<p>This code is ok if you don't care at all about performance, but in a VR or AR app you can quickly add milliseconds frame time and make yourself sick writing relatively simple code in this style.