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 mwozniak93 · Oct 04, 2015 at 01:17 AM · poolingobject pool

Object pooling for many different Prefabs

Hi I am in thinking about pooling monsters...

For example I want to have 20 bats, 10 snails on the scene.

I know that there is no way that player will see more then 3 monsters at once (with same type like snail) So I would like to have a pooling system for monsters: I would only instantate 3 bats and 3 snails. When player comes close to the monster I detect it OnTriggerEnetr2D and simply pool an monster.

That's sounds good, but with my knowledge I would need to create an global MonsterPoolManager where I would have to makre GameObject[] Bats, GameObject[] Snails etc... I would also need to have seperate counter(pointer to index) for each of them. What becomes silly if I would have about 30 types of monsters in whole game... I was thinking about puting all Monsters in one array and just pool them by searching in the loop by id or name, but that wouldnt be a very efficient way right? I mean if there was about 10 placeholders for monsters it would mean that I have to do the loop through all monsters array ten times... I guess it could cause lags...

What would be a shortcut for that? I feel that I don't know something important, or I didnt come up with a proper idea...

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ChecePuppu · Jan 12, 2017 at 03:53 PM

You could either combine the behaviours of the bat and snail scripts into one and then just have an int to define which it is, then just pool the "generic" monster (a monster with the combined behaviour) and change the int value defining the specifics of the creature just before you place it, or you could just have multiple seperate, tiny pools of each monster type for the level.

Comment
Add comment · 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
0

Answer by whynot660 · Jan 12, 2017 at 08:29 PM

you can use a 2d array with the id of the monster as lineIndex, you will get for example

    static  enum MosterIndex = { snail, bat, raven, ....}
 /*
  - make the monster id readable to in case you forget what is the index of a specific monster
  - then access to a specific type of monsters would be easier
  - if the number of monsters is different you can use a List 
   this is the simplest way
 */
 
 MonstersArray[MonsterIndex.snail, index]  ;

   

 

  


Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Object Pooling Help 0 Answers

Questions about Object pooling 0 Answers

Unity Compiler Error not all paths return a value - Object Pooling 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