In Unity3D, I have a
MonoBehaviour which gets added to game objects. I'm adding a
string "name" field to it. I'd like the default value for the name to be the name of the game object the component is added to. Is there an easy way to do this? Some more details:
The component is an existing one to which I'm adding the name field. In old versions, the name was always the name of the game object, and this is a new feature to allow them to be different.
The common case is (still) for the name to be the name of the game object, so having that as the default would simplify the process of adding the component to a new object.
Ideally, deserializing an old scene will fill in the default, so updating scenes takes zero effort. I'm less concerned about this than about newly created scenes/objects.
The component already uses a
I don't care about updating the name in the component if the game object's name is changed, or if the component values are pasted into a different game object.
One way I can think of is to add a
bool "override name" to the object. If the
bool is unchecked, it uses the default name (the game object); if it's checked, it uses the new field. But I'd like to avoid adding complexity to the GUI to support it. The whole point of my request is to add the new functionality (overriding the name) without adding steps to the creation workflow.