{"id":1219,"date":"2011-05-24T11:16:49","date_gmt":"2011-05-24T10:16:49","guid":{"rendered":"http:\/\/www.feedingedge.co.uk\/blog\/?p=1219"},"modified":"2011-05-24T11:16:49","modified_gmt":"2011-05-24T10:16:49","slug":"the-power-of-the-prefab-unity3d","status":"publish","type":"post","link":"https:\/\/www.feedingedge.co.uk\/blog\/2011\/05\/24\/the-power-of-the-prefab-unity3d\/","title":{"rendered":"The power of the prefab -unity3d"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=epredator\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p>I have been diving into some more <a href=\"http:\/\/www.unity3d.com\">unity3d<\/a> development for some mini games for a gaming startup. Once again the subtle power of Unity3d shone through with what is in effect object inheritance.<br \/>\nIf you create an object on the stage it is a single instance, copying and duplicating that makes new instances. These are completely unrelated with the exception of any materials or script references they have.<br \/>\nHowever, if in the project file area you do the magical &#8220;create prefab&#8221; and then drag the object from the stage back onto the prefab you have created it automagically becomes a class.<br \/>\n<a href=\"http:\/\/www.feedingedge.co.uk\/blog\/wp-content\/uploads\/2011\/05\/UnityScreenSnapz014.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.feedingedge.co.uk\/blog\/wp-content\/uploads\/2011\/05\/UnityScreenSnapz014.jpg\" alt=\"\" title=\"Unity prefab\" width=\"126\" height=\"292\" class=\"alignleft size-full wp-image-1220\" \/><\/a><br \/>\nNow if you use the prefab object to populate the stage you end up with multiple instance of the same base object. Are all you objects too big? resize one on the stage and say &#8220;apply to prefab&#8221; it will ripple the change back to the base class and then back out to all the instances.<br \/>\nEach object can still have its own configuration. e.g. drop a rotation script on the prefab, they will all rotate on stage\/scene.<br \/>\nHowever if you expose parameters on that script you can set the rotation speed individually for each of those objects. i.e. overide the defaults.<br \/>\nThe visual nature of the objects and the scene and the visual application of changes is a great teaching tool for those people not yet quite grokking the whole class and instance thing in regular code.<br \/>\nIt would be nice if when creating a new object in the scene you were prompted to make it a prefab and 9 times out of 10 that&#8217;s what you want to do, but thats a minor thing.  <\/p>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.feedingedge.co.uk%2Fblog%2F2011%2F05%2F24%2Fthe-power-of-the-prefab-unity3d%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:80px;\" allowTransparency=\"true\"><\/iframe><div name=\"googleone_share_1\" style=\"position:relative;z-index:5;float: right; margin-left: 10px;\"><g:plusone size=\"tall\" count=\"1\" href=\"https:\/\/www.feedingedge.co.uk\/blog\/2011\/05\/24\/the-power-of-the-prefab-unity3d\/\"><\/g:plusone><\/div>","protected":false},"excerpt":{"rendered":"<p>I have been diving into some more unity3d development for some mini games for a gaming startup. Once again the subtle power of Unity3d shone through with what is in effect object inheritance. If you create an object on the stage it is a single instance, copying and duplicating that makes new instances. These are<br \/>\n            <span class=\"excerpt-readmore\"><a class=\"more-link\" href=\"https:\/\/www.feedingedge.co.uk\/blog\/2011\/05\/24\/the-power-of-the-prefab-unity3d\/\"><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-1219","post","type-post","status-publish","format-standard","hentry","category-unity3d"],"_links":{"self":[{"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=1219"}],"version-history":[{"count":2,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1219\/revisions"}],"predecessor-version":[{"id":1222,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1219\/revisions\/1222"}],"wp:attachment":[{"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feedingedge.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}