- Home /
 
               Question by 
               ViIIain · Jul 10, 2014 at 02:28 PM · 
                find-gameobject  
              
 
              Find all GameObjects containing scripts, which are derived from abstract class.
Hello,
I have a problem finding all GameObjects in the scene containing scripts, which are derived from an abstract class.
Situation looks like this:
 public abstract class IAbstractInterface: MonoBehaviour
 {
 }
 public class Item_I_Need_To_Find1 : IAbstractInterface
 {
 }
 public class Item_I_Need_To_Find2 : IAbstractInterface
 {
 }
 ....
How can I find all gameobject in the scene containing Item_I_Need_To_Find(%number%) scripts? 
I would really appreciate any help.
Thanks in advance.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by vexe · Jul 10, 2014 at 02:37 PM
Use UnityEngine.Object.FindObjectsOfType< IAbstractInterface >(); That will give you back all objects that inherit IAbstractInterface 
I was trying FindObjectOfType(typeof(IAbstractInterface )) and it didn't work.
Your solution works like a charm. Thank you!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                