Question by
WILEz1975 · Sep 21, 2015 at 12:30 AM ·
componentsdeletespecific
Delete all component but not Renderer/MeshFilter at RunTime
I would destroy all the components of a gameobject except Transform (of course), the Renderer and MeshFilter ...
In practice I instantiate my object, but then I would take away all the scripts that are not those three.
How can I do?
My try:
void CreateMiniMesh () {
ObjectMesh= GameObject.Instantiate(MyOriginalObject);
Component[] AllChidren= ObjectMesh.transform.GetComponentsInChildren<Component>();
foreach (Component childrens in AllChidren) {
if(!childrens.GetComponent<Renderer>()&&
!childrens.GetComponent<Transform>()&&
!childrens.GetComponent<MeshFilter>()){
Destroy(childrens.GetComponent<Behaviour>());
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Player not deleting 2 Answers
Components not recognized. 1 Answer
component greyed out 1 Answer
Seeking feedback on my ECS/Jobs design before I start investing the time to code it 0 Answers