- Home /
Is it possible to create a custom Game Component?
I currently just started using Unity 4.6. I just finished the 2nd of the 3 main project tutorials in an effort to get comfortable using Unity. In the tutorial videos, they make reference to a GUIText Game Object that can be added from the Hierarchy; however it doesn't look like this is still available in the more recent versions. I got around this by creating a Blank Game Component, and then adding the GUIText component from Rendering-> GUIText; however this adds an extra step. Is there a way to save this "base" game component as a custom? Any help is appreciated. Thanks,
Joey
Answer by tanoshimi · Jan 24, 2015 at 03:25 PM
Every script you write and attach to a gameobject is a custom component - that's what they are ;)
But don't use GUItext - it's deprecated and has been replaced by UI introduced in Unity 4.6 (there's tutorials in the Learn section of this site)
I did see the Canvas/UI Functionality - and will definitely check out the Learn section to find out more. For the purposes of the Tutorial I was trying to follow along and noticed the difference. Thanks for the info!
Either way - I guess my question still stands. Is it possible to create a custom component that can be added from the Hierarchy/Create menu? One that has preset values that I have set previously. Would I use a Prefab for this?
You just add the AddComponent$$anonymous$$enu attribute to the top of your class - http://docs.unity3d.com/ScriptReference/AddComponent$$anonymous$$enu.html
This will work perfectly along with Owen's suggestion below. Thanks again.
Answer by Owen-Reynolds · Jan 24, 2015 at 04:52 PM
As you note, the cheap way is to make a prefab, set up the way you like. For example, the Legacy particle system also no longer has an entry under Create, and also needs to be assembled from (3!) components. Easy to just drag-create a prefab after the first time you make one.
The fancy way to do exactly what you want is an Editor Script. They can run code in the Editor (create Components, attach to gameObjects, ...) put tools in the Inspector, and can(?) be set to run from dropDowns.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181400im_/https://answers.unity.com/themes/thub/images/avi.jpg)