- Home /
Why unity executes scripts in prefabs which are not on scene?
Why? What is the reason. How to turn this feature
off?
Scripts are marked with [ExecuteInEditMode] attribute, which is needed. The result is some gameobjects are generated and a thrown on a scene for no reason, with now parents and no purpose.
PS. Should clarify tha this happens for objects which update their state on OnValidate event, which is called every time it is selected in Project view.
Answer by HappyMoo · Jan 12, 2014 at 03:45 PM
Check activeInHierarchy on yourself and don't execute code if you are not active/inScene...
This doesn't work anymore as prefabs are visualized in some kind of a scene and hence exist in a hierarchy since the new prefab system (from 2018 I think)
Your answer
Follow this Question
Related Questions
Changes via script in prefab mode not applied to instances 0 Answers
Prefab linking 1 Answer
Adding a child via code in edit mode won't work for prefab instance 0 Answers
How do i make a cube "slide"and fixed on a rail? 0 Answers
Component Value Reverts to Prefab Value under certain conditions when Scene is Tested 1 Answer