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 joemane22 · Nov 14, 2015 at 05:07 AM · gameobjectdestroycomponentpooling

Object Pool and components

Hi, I am using a simple object pool for use with drawing generic objects such as lines, rectangle, circles, curves, etc. Sometimes I add other components to them such as BoxCollider2D, FollowMouse, etc. The question I have, what would be the best way of handling it?

Right now I add the components when I need them then destroy them when I put the object back into the inactive list but after coding this I thought, this kind of defeats the purpose of an object pool if I am just going to create and destroy the components but not the game objects.

What would be the best way to eliminate the need to destroy components after creation. Also, it is not viable to create a pool for each type of object because sometimes I add components outside of the initial script the pool is in so I cannot think of every combination of components that I might need.

Thanks in advance for any help!

Comment
Add comment · Show 1
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 NextUnity · Jul 11, 2020 at 07:02 AM 0
Share

Which method did you use at that time!? I have the same problem with you. Thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pekalicious · Nov 16, 2015 at 12:13 AM

True, there is no purpose for you to use an object pool if you are going to be destroying them. Typically an object pool has a Create method that initializes a component's variables and a Release method that disables the game object and/or component and resets its position to a default location.

But the question is, why do you think you need an object pool for everything? Are you going to be creating different components that each has more than 1000 objects in the scene?

Remember, an object pool is for pooling a single "type" of entity. I.e. if you have 1000 bullets, then you have one bullet prefab and an object pool that controls those prefabs (Creates and Releases when appropriate). That bullet prefab can have any number of components. The object pool will make sure to config each component (based on your parameters) when creating.

Now, for something like a player game object, or even an enemy game object, that you will most likely only have a few in the scene, there's no need for an object pool.

Comment
Add comment · Show 3 · 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 joemane22 · Nov 16, 2015 at 01:40 AM 0
Share

I understand what your saying and without going into too much detail I'm making a reusable primitive drawer which will be used for drawing a map section so there will be a lot being created and destroyed. This map is also editable hence the nerd for different components.

I am just tryingto see if there is a similar method for components so I can add them if needed but not destroy them afterwards but are able to be reused if needed.

avatar image pekalicious joemane22 · Nov 16, 2015 at 01:53 AM 0
Share

When you say "drawing a map section", are you talking at runtime? As in, the player will be able to draw and edit a map while he's playing the game? And he will also be able to attach components to different sections of the map? If so, then, as far as I know, I don't think there is a way to remove a component without destroying it. The only (ugly) way I can think of is having a prefab game object for each component, and adding the game object as a child to the map section. That way you can disable the game object and reuse it and you will only need one object pool for each type of component, but all of them will be prefabs, so the code is the same.

avatar image joemane22 pekalicious · Nov 16, 2015 at 06:28 AM 0
Share

Yes that's what I was talking about and thanks for your time, since there is no way of doing what I was wanting to do I went a different rout and wrote a static class that will run delegates on game objects, it can be created once and reused, which is what I was ai$$anonymous$$g for. Even though you didn't suggest it you allowed me to move towards the right direction and have my code running as expected, thanks for the nudge!

BTW the map is too large to be creating everything then just moving the camera around so I wanted to be able to load the information in view then just draw those without continuiously creating a destroying objects. Sorry for not being too clear on that just figured it wasn't relevant to the question.

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

40 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

Related Questions

Destroying object multiple times. 0 Answers

If you want to destroy the game object, please call 'Destroy' on the game object instead. 1 Answer

Is there a way to refer to the only script the object has without naming the script? 2 Answers

Keep GameObject destroyed on returning to the scene 1 Answer

Make an object move from Point A to Point B then back to Point A, and then destroy itself 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