• 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 c$$anonymous$$ld, and a support beam underneath as another c$$anonymous$$ld. The whole t$$anonymous$$ng is exported as a single FBX file, but not collapsed so I can access the c$$anonymous$$ldren individually in Unity.

I wrote a small script that is attached to the GameObject, w$$anonymous$$ch 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 $$anonymous$$des them. My question is, since the "addons" are not being destroyed but just $$anonymous$$dden, 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 t$$anonymous$$s, 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

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 t$$anonymous$$s 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 t$$anonymous$$s approach.

When using Instantiate and Destroy, the object is not present in memory before it is instantiated. W$$anonymous$$le 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 $$anonymous$$dden (gameObject.active = false), than if they are visible (gameObject.active = true). T$$anonymous$$s is because the components wit$$anonymous$$n 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
avatar image PetterDK · Mar 06, 2012 at 04:55 PM 1
Share
avatar image PetterDK · Mar 07, 2012 at 11:29 AM 1
Share
avatar image Kaldrin · Nov 04, 2020 at 12:09 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

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

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

Why is Unity loading disabled GameObjects at scene start? 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