Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MilKID · Jan 29, 2017 at 09:41 AM · poolingobject pool

Unity Compiler Error not all paths return a value - Object Pooling

So I have the following problem and I am pretty sure it is something super simple but i just can't figured it out.

So in my script I am creating a List of Platforms and Shuffle them to randomize them. And what i want to do is object pooling.

This part of the script should be used to find platforms that arent active and then use them and if there arent any unactive ones it should create a new one.

Now Unity says Assets/Scripts/PlatformPooler.cs(39,20): error CS0161: `PlatformPooler.GetPooledPlatform()': not all code paths return a value

but the way I see it it does always return a value since if there isnt an inactive platform it does instantiate a new one.

Here is my code:

     public GameObject GetPooledPlatform ()
     {
         for (int i = 0; i < pooledPlatforms.Count; i++) 
         {
             if (!pooledPlatforms [i].activeInHierarchy)
                 return pooledPlatforms[i];
             else 
             {
                 GameObject obj = (GameObject)Instantiate (platform [i]);
                 obj.SetActive (false);
                 pooledPlatforms.Add (obj);
                 Debug.Log ("Added new Platform");
                 return obj;
             }
         }
 
     }

I am pretty sure its just a minor error but I really can't see it. I hope somebody can help. Thanks in Advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HenryStrattonFW · Jan 29, 2017 at 02:33 PM

I'm fairly certain the issue is that whilst your if/else statement covers return calls in each, they are inside a for loop, and therefore a chance that the if/else statement will never get reached (if you pooledPlayforms list is empty for example).

try just putting a "return null;" before the very end of the function, that should clear up the error. It's also a good place to put an error log perhaps letting you know that you've requested a pooledPlatform but don't have one available. Or alternatively have the pool automatically grow when this happens.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MilKID · Jan 29, 2017 at 04:03 PM 0
Share

thank you very much, that solved my problem :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

90 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object Pooling Help 0 Answers

Questions about Object pooling 0 Answers

How can I fix my object pool to continue after original pool is exhausted? 0 Answers

Can someone post a generic object pool script? 4 Answers

Could I get an explanation of object pooling and how to do it? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges