bug from RequireComponent

there is a bug about AddComponent and [RequireComponent]

follow this

step1 right click gameObject inspector and add a new C# Component named “MyTest” then click to open with MonoDeveloper

step2 write code like this

[RequireComponent(typeof(YourComponent))]
public class MyTest:MonoBehaviour
{

}

and, run in editor… so, YourComponent will not be added.

step3 remove MyTest from gameObject and add it again, YouComponent will successfuly be added.

this bug will save in project. if you don’t do step3… in ver 4.3.4 4.5

I don’t think this is a bug. If you add a RequireComponent, it will be considered from then on, but not for already existing game object, prefabs, … . This may lead to very annoying results, that prefabs that worked suddenly break because this component was automatically added, but the fields were not properly initialized. Or if you add a wrong type there, all you game objects would suddenly get that component an you would need to delete them all manually.

yeah ,thanks .

so, may be not a bug. but if it happend ( may be happend offen) that difficulty of find out what reason…

because it looks normally…

I understand what you mean. But I think Unity made the right decision to say, when someone modifies a script, they have to make sure it keeps running as expected.