<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Prefab on Huy Minh Ha</title><link>https://minhhh.github.io/tags/prefab/</link><description>Recent content in Prefab on Huy Minh Ha</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 06 Jul 2017 00:00:00 +0700</lastBuildDate><atom:link href="https://minhhh.github.io/tags/prefab/index.xml" rel="self" type="application/rss+xml"/><item><title>Unity Prefab Best Practices</title><link>https://minhhh.github.io/posts/unity-prefabs-best-practices/</link><pubDate>Thu, 06 Jul 2017 00:00:00 +0700</pubDate><guid>https://minhhh.github.io/posts/unity-prefabs-best-practices/</guid><description>&lt;p&gt;&lt;strong&gt;Link prefabs to prefabs; do not link instances to instances&lt;/strong&gt; This is from &lt;a class="link" href="http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/" target="_blank" rel="noopener"
 &gt;50 Tips for Working with Unity&lt;/a&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use GameObject.Find to establish links between instances&lt;/strong&gt; if you have to. It&amp;rsquo;s best to not having to establish links between instances and use prebabs instead. &lt;strong&gt;Don&amp;rsquo;t&lt;/strong&gt; link instance to instance like this article suggests (&lt;a class="link" href="https://akbiggs.silvrback.com/please-stop-using-gameobject-find" target="_blank" rel="noopener"
 &gt;https://akbiggs.silvrback.com/please-stop-using-gameobject-find&lt;/a&gt;)
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Apart from UI component, refrain from using GameObject.Find&lt;/strong&gt; because there are many better alternatives such as using interfaces, dependency injection, design patterns and so on.
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Editor script to warn you of missing links in the Editor&lt;/strong&gt; like this one: &lt;a class="link" href="https://github.com/redbluegames/unity-notnullattribute" target="_blank" rel="noopener"
 &gt;https://github.com/redbluegames/unity-notnullattribute&lt;/a&gt;. However, it will not work when you use the same prefab for multiple gameplay modes, each with its own set of required component. In that case, you will have to use inheritance or duplicate code in a new component.
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Remove prefab links from scene object&lt;/strong&gt; (&lt;a class="link" href="https://github.com/minhhh/unity-tips/blob/master/README.md#tips-using-editors" target="_blank" rel="noopener"
 &gt;https://github.com/minhhh/unity-tips/blob/master/README.md#tips-using-editors&lt;/a&gt;)
&lt;br/&gt;&lt;/p&gt;
&lt;h2 id="references"&gt;References
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/" target="_blank" rel="noopener"
 &gt;50 Tips for Working with Unity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://akbiggs.silvrback.com/please-stop-using-gameobject-find" target="_blank" rel="noopener"
 &gt;Unity Devs, stop using GameObject.Find!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>