Editor Scripting: Creating new component and setting fields doesn't seem to work?

Hey all,

I am writing a script that runs in the editor using [ExecuteInEditMode]. During the execution of the script I create new components, and then try to set the values in those new components.

The new components are properly getting created, and the reference given back from AddComponent() seems correct, however when I use that reference to modify the fields on the newly created components, the values don’t get applied.

MyComponent newComponent = child.gameObject.addComponent<MyComponent>();
newComponent.customField = "Foo";

After this runs, looking at the object with the new component in the editor, the component is there, bu customField is blank rather than being “Foo”.

sigh… Please ignore this. As usual, spend 30 minutes beating you head against a wall wondering why it isn’t working, then post in the forums and then realize your mistake 5 minutes later.

This works perfectly. The problem was with how I was adding the components when the object already had the component before hand.