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
4
Question by ronronmx · Jan 23, 2012 at 06:08 PM · gameobjectmemoryactive

Do un-active game objects still use memory?

My title is a little vague, so let me explain...

I created an ramp with some "addons" attached to it in my 3D program. The ramp is the parent, then it has some arrows pointing in the direction you need to go as a child, and a support beam underneath as another child. The whole thing is exported as a single FBX file, but not collapsed so I can access the children individually in Unity.

I wrote a small script that is attached to the GameObject, which lets me assign the arrows and the support beam as "addons", and makes it possible to "deactivate" or "activate" those "addons" to make them visible or invisible.

They key word here is "activate", as in gameObject.active = false/true. It does't destroy or instantiate the addons game objects, it just hides them. My question is, since the "addons" are not being destroyed but just hidden, is my object just as expensive with the addons invisible then with them visible? Do I need to "destroy" and "instantiate" them if I want to save memory and speed?

Thanks in advance for any clarification on this, and thanks for your time! Stephane

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 MithosAnnar · Mar 06, 2012 at 04:39 PM 0
Share

finally, someone with a question (I think) I can answer.

Activating and deactivating is more efficient if you have a lot of update functions attached to whatever it is you are trying to activate/deactivate.

1 Reply

· Add your reply
  • Sort: 
avatar image
12
Best Answer

Answer by PetterDK · Mar 06, 2012 at 04:22 PM

I am currently wondering about this very same question, but can't seem to find a straight answer anywhere.

So far what I've gathered is that when you use the gameObject.active toggle, none of the components on that gameObject will receive any updates. That means that you are saving performance in the sense that the inactive object is not considered at runtime, before it is activated. The object DOES exist in memory though when using this approach.

When using Instantiate and Destroy, the object is not present in memory before it is instantiated. While that means saving memory usage, instantiating the object seems to be a more expensive process than activating an inactive object. Especially if it's a complex object, you will likely take up some performance when instantiating.

To answer your question, then: No, your objects are not as expensive when they are hidden (gameObject.active = false), than if they are visible (gameObject.active = true). This is because the components within the object are not receiving any updates from Update, FixedUpdate or LateUpdate, and of course the fact that it's not being rendered.

If you want to save memory per se, then yes – you will have to use Instantiate/Destroy.

Comment
Add comment · Show 4 · 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 MithosAnnar · Mar 06, 2012 at 04:37 PM 1
Share

"but can't seem to find a straight answer anywhere."

want a straight answer?

Heres one straight up!

(through it may or may not be incorrect)

you are correct. except for the line:

If you want to save memory per se, then yes – you will have to use Instantiate/Destroy.

one line of code is better than 2. (I should think anyway)

avatar image PetterDK · Mar 06, 2012 at 04:55 PM 1
Share

Yea, I guess I did put a straight answer in there myself :) Totally unintentionally, of course..

But yes, I think you are right in saying that one line of code is better than two..

avatar image PetterDK · Mar 07, 2012 at 11:29 AM 1
Share

Oh, and ronronmx – If you found my answer useful, please send some karma my way.. Thx :)

avatar image Kaldrin · Nov 04, 2020 at 12:09 AM 0
Share

Thanks for your explanation! So yeah, an unexisting gameobject is still far better tahn an inactive one, but I guess that for menus and GUI elements you can't really not just disable and enable objects

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Deactivate an object - and all scripts in that object deactivated? 1 Answer

Why is Unity loading disabled GameObjects at scene start? 1 Answer

What do the "active" and "static" checkboxes do? 1 Answer

inactive objects impact on memory 1 Answer

How much memory does a GameObject consume? (iOS) 0 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