The power of the prefab -unity3d

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 completely unrelated with the exception of any materials or script references they have.
However, if in the project file area you do the magical “create prefab” and then drag the object from the stage back onto the prefab you have created it automagically becomes a class.

Now 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 “apply to prefab” it will ripple the change back to the base class and then back out to all the instances.
Each object can still have its own configuration. e.g. drop a rotation script on the prefab, they will all rotate on stage/scene.
However if you expose parameters on that script you can set the rotation speed individually for each of those objects. i.e. overide the defaults.
The 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.
It 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’s what you want to do, but thats a minor thing.

Leave a Reply

Your email address will not be published. Required fields are marked *

EXCu Emg

Please type the text above:

This site uses Akismet to reduce spam. Learn how your comment data is processed.