- Home /
can't dynamically add scripts to gameObjects via Editor
Hello all,
I am attempting to add scripts to child gameobjects in the editor.
Calling:
child.gameObject.AddComponent<scriptHere>();
in a loop works perfectly during runtime. Also performing any operations of children such as getting child name works find also.
However using the same line of code in a script being called by an editor button click throws the error:
The type or namespace name scriptHere could not be found. Are you missing a using directive or an assembly reference?
Both the script and the called script derive from monobehaviour.
Any idea why this would be so?
your code starts:
public class scriptHere: $$anonymous$$onoBehaviour {
?
Yes, both scripts, the one calling the sript and the called script both derive from monobehaviour. Added that above.
Is 'scriptHere' placed in a namespace that you forgot to import/use? Or did you place 'scriptHere' in the Editor folder (you shouldn't)?
ps. Is your code able to compile? (Does the error message persist when you clear the console?)
I'm just using the default supplied namespace. The script resides in the Scripts folder, Editor script lies in the Editor folder like it should. The error message does persist after cleared. It is just strange the same code works in runtime if I place the function call in the Start() function. I can try start from scratch in at new project and see what I can figure out.
Your answer
Follow this Question
Related Questions
Issue with a Mecanim motion reference in synchronized layers 0 Answers
Is it possible to detect changes to a different component within an editor script? 0 Answers
applying toon shading to all 3d meshes at once 1 Answer
Drop down selection list 1 Answer
How to record hideFlags for Undo/Redo 0 Answers