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 /
avatar image
1
Question by spanagiotis · Feb 09, 2013 at 12:20 PM · gameobjectdisablesetactiveenable

Alternatives to GameObject.SetActive(...)

So I have recently come across an issue activating/deactivating game objects, its become to slow of an operation. More specifically, whenever one of my spawn triggers are executed the game pauses for a brief moment as the target gameobject is enabled. I have taken a better part of the day to try and find a work around to this issue, but haven't had much luck.

I'm not doing any instantiation, this is a pure .SetActive(true) call on a game object and I've narrowed it down to being specifically that being the cause. My ideal solution would be to somehow toss the SetActive stuff onto a new thread, but I'm not even sure that's possible, or how to do it if it was.

Curious if anyone has any good alternatives to SetActive()?

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 Jason-King · Apr 15, 2013 at 04:45 PM 0
Share

I'm seeing this as well - does anyone know if that it is normal for SetActive to hang/pause the game for a frame?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Brian-Kehrer · Apr 15, 2013 at 04:58 PM

Have you deep profiled this? Calling SetActive should not be an expensive operation. More likely, something is happening in Start() that is expensive, and causing your aforementioned issue.

Of course, depending on what you actually want to disable, there are plenty of alternatives to turning off the gameObjects, such as disabling the individual components. What is it you are actually trying to accomplish, and what components are attached to the object? These are generally the causes of slow activation.

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 Jason-King · Apr 15, 2013 at 05:12 PM 0
Share

I've investigated further and deter$$anonymous$$ed that I'm getting the same issue as http://answers.unity3d.com/questions/210896/rendertexturesetactive-huge-profiler-spikes.html?page=1&pageSize=5&sort=votes. If I set to render maximized the problem goes away - but that's not really an answer to this issue. Additionally I'm not seeing the spike when I SetActive(false) on a general gameobject with mesh-based children, but I am seeing when I SetActive(false) on the mesh-based gameObjects themselves.

avatar image
0

Answer by chmodseven · Jun 08, 2015 at 11:00 AM

I am also encountering a weird variant of this.

When I initialise my scene, I am using GetComponentsInChildren to loop through and find all UGUI child game objects containing a particular component, so I can cache them in a dictionary for faster access later. The search starts at each canvas root parent in the scene, and all child objects are active. The weirdness comes in with the root parent being enabled or not.

Now, if the canvas object is enabled, no problem - it all goes nice and fast. But if I set the canvas disabled in the scene (which is preferable, to avoid flickering) then GetComponentsInChildren runs very slow and adds up to 5 seconds to startup. No problem, you say, just SetActive it before you start getting the components: but when I tried that, the slowness doesn't go away even though effectively the objects are now in the exact same state as if I'd saved them as active in the scene. Weird.

Currently I am getting around it all by leaving the parents active but turning the camera off until I've done all the caching, to avoid the flickering. But I would much prefer to understand why this is happening like this, and why the mere presence of a disabled parent makes GetComponentsInChildren so considerably slow in the first place.

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

11 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

Related Questions

Calling setActive(false) on a disabled object? 3 Answers

How to disable an array of projectors 2 Answers

Help With Disabling/Enabling single GameObject 1 Answer

Enable/Disable Game Object With GUI Button 1 Answer

how to perform undo action in unity? 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