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 /
avatar image
1
Question by MrJBRPG · Mar 31, 2017 at 02:44 PM · setactivespawning problemsobject pool

Object no longer spawn through object pooler

Right now, I am attempting to get a turret to continuously fire bullets and re-use any that are inactive. However, when I run the game in editor mode, the turret does shoot a few bullets, but then it stops spawning bullets that are inactive.

My object pooler is based on the following tutorial right at the bottom comment with all the code: https://www.raywenderlich.com/136091/object-pooling-unity

Code for turret firing bullet: alt text

Notice the debug passes through each time when a new bullet gets created / active, but after a few successful creations, it stops working altogether.

Here is how the bullets get made: alt text

screen-shot-2017-03-27-at-43414-pm.png (174.6 kB)
screen-shot-2017-03-27-at-44332-pm.png (74.6 kB)
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
1
Best Answer

Answer by Bunny83 · Mar 31, 2017 at 06:20 PM

That object pool implementation is inherently bad. A couple of days ago there was another question about pretty much the same pooling script. I posted a simpler and way better implementation over here.

However your main problem is most likely that you do not re-initialize your bullet. You call initializeBullet from "Awake". However Awake is only called once in the lifetime of an object. So deactivating / activating won't call it again. So either make initializeBullet public and call it after you aquired the bullet from the pool, or perform the initialization in OnEnable instead of Awake. OnEnable will be called each time the object is enabled / activated.

Another thing that doesn't make any sense in your code is that you wrap only a part of your code in that null-checking if statement. Either put everything that accesses the "bullet_clone" in the if or remove it completely. Removing it of course assumes that GetPooledObject never returns null.

Finally, don't post code as images / pictures. If you have trouble to get the syntax highlighting working here on UA, have a look at the user guide

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 MrJBRPG · Mar 31, 2017 at 09:56 PM 0
Share

Thanks, I figured that re-activated objects always go through OnEnable shortly after I observed the error. I am looking forward to learning more about Object Pooling anyways.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Object Pooling with setActive function help 1 Answer

How do you call child in group of elements? 2 Answers

physics.OverlapSphere colliders 1 Answer

Unity object pooling works for first ten seconds and then all objects go deactivated. How do I fix this? 0 Answers

How can I control Spawn speed/rate from an Object spawner? I'm new to Unity and scripting, and would like to delay the spawn rate of objects coming out of an ObjectPooler. 1 Answer


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