Question by 
               Surface_ketch · Apr 06, 2016 at 06:16 PM · 
                errorgameobjectreturnpooling  
              
 
              Not all code paths return a value
 public GameObject GetPooledObject()
     {
 
         for (int i = 0; i < pooledObjects.Count; i++)
         {
             if (!pooledObjects[i].activeInHierarchy)
             {
 
                 return pooledObjects[i];
 
             }
         }
         
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Cepheid · Apr 06, 2016 at 06:21 PM
Hi there @Surface_ketch
You are only returning a value if the conditional is met. This means that the method will be unable to return anything if the conditional is not met. To fix this, simply return a null or default value after the for loop like so:
     public GameObject GetPooledObject()
     {
 
         for (int i = 0; i < pooledObjects.Count; i++) {
             if (!pooledObjects [i].activeInHierarchy) {
 
                 return pooledObjects [i];
             }
         }
 
         return pooledObjects = null;
     }
That should fix your problem, I hope this helps! :)
Your answer
 
 
             Follow this Question
Related Questions
Array index out of range(C#) 1 Answer
NullPointException Object not found, caused by a variable not accepting value? 0 Answers
Setting EventTrigger in Unity with JavaScript 0 Answers
Object reference; sometimes works but sometimes doesn't??? 2 Answers
Can't add Orbital script - "The script needs to derive from MonoBehaviour!" 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                