- Home /
Is there a way to run script when adding object to scene?
I'm child-ing a prefab (containing a trigger sphere collider) onto certain objects in my scene, and I've figured out a way to set the collider radius in accordance with the parent's scale, but am wondering if there's a way to have this automatically set when I drag the prefab onto the object, rather than at runtime?
Answer by Paulius-Liekis · Feb 28, 2012 at 11:29 AM
EditorWindow.OnHierarchyChange perhaps? Of course that means you would have to have some EditorWindow open.
Would it be as an editor script? I'm not too familiar with editor scripts… I'll look into it though, thanks!
@script ExecuteInEdit$$anonymous$$ode() perhaps will help
Yes, it's an editor script. You class has to be derived from EditorWindow and you have to implement OnHierarchyChange.
@alec, ExecuteInEdit$$anonymous$$ode has nothing to do with this - it is used to telling Unity that it should execute $$anonymous$$onoBehaiour in Edit mode.
Yes, I understand that. Perhaps I misunderstoo the question; I thought Essential was doing something in runtime, and also wanted to do it while editing, in which case ExecuteInEdit$$anonymous$$ode and a quick transform.parent check would be a potential resolution.
Your answer
Follow this Question
Related Questions
making prefabs at runtime? 2 Answers
Allowing users to import their own UnityScript/JavaScript into the game at run time 1 Answer
load in Hierarchy 1 Answer
Playing AudioClip in Runtime 0 Answers
Runtime mesh generation 2 Answers