- Home /
Changing script name displayed in inspector
Hi,
I have multiple instances of a script on my game object and would like to change their displayed mono behaviour type displayed name for the component in the inspector. Can it be done via my custom editor for this component, and how ?
Answer by lodendsg · Dec 09, 2014 at 07:33 AM
This is an old question however for my purposes you can set [AddComponentMenu("name as string")]
This will set the display name of the component and can put the component under a given menu; handy if you are a content/asset developer for example
[AddComponentMenu("myName/myProduct/v1/dohicky (v1)")]
and
[AddComponentMenu("myName/myProduct/v2/dohicky (v2)")]
This will cause the Add Component button in the inspector to show a folder structure also if they search for dohicky they will see dohicky (v1) and dohicky (v2) even if the scripts them selves have the same name. Again probably not what the OP was looking for but the question has come up several times RE set or change component display name so thought it might help others.
Answer by landon912 · Aug 31, 2012 at 01:04 AM
You want to change the script name? If so then you will need separate scripts and then you can rename each in the editor to whatever you need.
This is exactly what I do not want to do (split to multiple script), I suspect that components name is necessary for getting the component via reflection so changing it is not possible. They should probably let us modify that at some point but its those kind of things that are so not important... oh well...
Ok you could have said that it in the question, and also you should post this as a comment to my failed answer.
Answer by landon912 · Aug 31, 2012 at 07:54 PM
In a script you can make a copy of the script useing AddComponent and then store it in a var. That way you can access that script useing that var. You should put this in the function Awake so that it's only creates a copy for the first one.
Your answer
Follow this Question
Related Questions
I'm having trouble getting the text in Unity's "text mesh" to change its text at runtime. 1 Answer
Is there any way to change order of inherited fields in inspector? 0 Answers
components and variables - inspector problems 1 Answer
Getting Another Object's ID with Colliders 1 Answer
Inspector:Reference a component in Assets, not in scene. 0 Answers