false negative "Can't Add Script" error

i’ve created a neeat little script for positioning objects. I just add it as a component. Its set to execute in editor, do some calculating, move the object into the right place, and then the script deletes itself. It works as designed, flawlessly, and in a fraction of a second

however, whenever i add it to an object, i get the error “Can’t Add Script” in a popup dialog box which blocks the cpu. I can tell because the script doesnt do its thing until after i dismiss that dialog. It does work fine though

I’m pretty sure this message is just unity interpreting the behaviour falsely as a problem. it believes it’s unable to attach the script presumably because it doesnt see it there, when it is infact doing its work and cleaning up.

how can i get rid of the extraneous error message?

I see you posted that as an answer, this is why you need to be careful with comments and answers. I thought someone else had answered this so I only stumbled across this by chance.

Anyway I converted that to comment so let’s see if we can get it working, try this:

#if (UNITY_EDITOR)
[ExecuteInEditMode]
#endif

That way it’ll run the code in EditMode if in the EDITOR and if not it should run it at Start if in play mode.

For what it’s worth, i eventually found a solution.

moving the DestroyImmediate() line from Awake, into Start, solves the issue. I’m not entirely certain why, but i’d guess start was trying to execute on the script which wasnt there by that time?