Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jun 08, 2015 at 03:36 PM by RLin for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by RLin · Jun 07, 2015 at 06:20 PM · objectperformanceoptimizationpool

Most performance friendly way to "unrender" a GameObject?

If I want to disable an object that is in an object pool system, which method would be the most performance friendly?

  1. Use setactive(false)

  2. Disable the renderers of it and its children

  3. Set its transform to somewhere extremely far away.

Note that the object in question does not move at all, so the only reason for its existence is the renderer. All three methods work in this situation, but only because the object has a renderer and nothing else.

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

6 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by RLin · Jun 08, 2015 at 03:29 PM

I tested the three methods myself and found that setting the object transform was the most performance friendly. Like I said, all three are viable options because the object only has a renderer. Thank you to those who posted answers. Also, @crohr, sorry for my stubbornness, but it paid off because my game now runs much faster.

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 crohr · Jun 08, 2015 at 06:00 PM 3
Share

I just want to clarify for future readers, that the selected method of moving the transform may be the most optimized for RLin, but can have side effects if you are not careful, because the GameObject is still active in the scene. Not trying to discredit the chosen solution, but what is optimized for one game may not be the best solution for another game.

avatar image RLin · Jun 10, 2015 at 11:57 AM 1
Share

The reason that I did not like the answer of using setactive is that I had a noticeable drop in framerate when it was used, but not with the other two methods.

avatar image Bunny83 · Jun 10, 2015 at 12:40 PM 0
Share

Even though it seems strange i have noticed the same thing, especially on android ( mobile in general ). Any kind of disabling the object has quite an impact on the framerate as the object has to be removed from the rendering queue.

I once made a Trackmania-style game for android (of course with track editor ^^) and the creating and destroying of the track parts took quite some time. So i build a transparent object pool, thinking it should boost the performance of adding / deleting parts. However the speed increase was just between 30% - 40%. However it caused hundreds of other problems since the object isn't destroyed, they keep references between the parts (took a while until i found the last reference). You really see strange things going on if there are dead references to diabled objects in a pool.

Finally i kept using the pool and used SetActive to disable them since it was already written and it gives you a slight boost.

$$anonymous$$eeping the objects active wasn't an option for me since the inpact on rendering performance was too much. This was mainly an issue for track loading and while using the track editor. It was more important to get a smooth racing game, even when the loading time is a bit longer ^^.

I gave you both an upvote. Especially: "what is optimized for one game may not be the best solution for another game". If optimising would be that easy, Unity would provide an general purpose "Optimise()" method ^^

avatar image
2

Answer by Pascal97 · Jun 07, 2015 at 07:08 PM

I am now 100% sure but I wouldn't recommend 3) cause the obkect still is in the scene as before and it doesn't change that much. 2) would only deactivate all renderes whereas 1) would also set all colliders and other components to inactive. I so would take 1).

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 RLin · Jun 07, 2015 at 09:00 PM 0
Share

If you read above, the object doesn't have any colliders, and exists only for the renderer.

avatar image
1

Answer by screenname_taken · Jun 08, 2015 at 03:21 PM

Use SetActive(false). That disables the object completely. So if you have something searching for stuff in the scene by name, Unity won't go over the disabled objects. If you just disable the renderer Unity will still check if it should do something with that depending on the rest of the scripts.

Try not to delete objects unless you really need to, as that will make garbage for the collector in the end.

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 kidne · Jun 08, 2015 at 05:53 AM

Set active to false! Because then it's also disabling renderers.

You could also the Destroy(this.GameObject) function if you won't be needing it anymore.

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 crohr · Jun 07, 2015 at 07:33 PM

I agree with Pascal, using SetActive(false) would be the preferred method for deactivating a GameObject for two reasons.

  1. Using SetActive(false) will set the GameObject to be disabled and will disable all components on the GameObject.

  2. SetActive(false) will also disable all of the child GameObjects.

Comment
Add comment · Show 5 · 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 RLin · Jun 07, 2015 at 09:00 PM 0
Share

If you read above, the object doesn't have any colliders, and exists only for the renderer.

avatar image crohr · Jun 08, 2015 at 06:38 AM 0
Share

I didn't mention anything about colliders, I mentioned other components, which could be anything including custom scripts, not just colliders. I stand by my answer which is using SetActive(false) is the most effective way of disabling a GameObject.

avatar image RLin · Jun 08, 2015 at 01:29 PM 0
Share

Sorry, I guess I wasn't specific enough. The object only has a mesh renderer, mesh filter, and transform. It does not have any scripts or other components. Because of this, all three of the options are viable for my situation, I just want to know which one will cause the least hiccups/lag.

avatar image crohr · Jun 08, 2015 at 02:32 PM 0
Share

You have three people now telling you that SetActive(false) is the way to go. I am not sure if you just don't like the answer or what. But the answer is without a doubt SetActive(false), the fact that you do or do not have additional scripts on the object doesn't change the answer.

avatar image RLin · Jun 08, 2015 at 03:34 PM 1
Share

Sorry about being stubborn, but after much testing I found that setactive is awful for performance. Setting the transform turned out to cause the least hiccups. I also changed the title and description to be more accurate.

  • 1
  • 2
  • ›

Follow this Question

Answers Answers and Comments

25 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

Related Questions

Should I pool an object that only spawn every second? 1 Answer

Object Pooling, have some question marks 0 Answers

Disable objects far away from player to make performance better 2 Answers

Object.get_name() performance 0 Answers

Merging together all GameObjects of an Array? 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