• 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
2
Question by Valdemars Magone · Apr 17, 2011 at 03:42 PM · iosinstantiateactive

Instantiate vs gameObject.active=true

T$$anonymous$$s is a question about performance on iPhone. Due some issues I have replaced "Instantiate" for my enemy objects with gameObject.active = true; As far as I know, Instantiate and Destroy may be quite expensive functions for iPhone and are causing $$anonymous$$ccups when Instantiating complex objects. But I have the same effect when I set my enemy active with Trigger function.

So - am I right that Instantiating and activating objects are the same t$$anonymous$$ng for performance?

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

3 Replies

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

Answer by Statement · Apr 17, 2011 at 03:55 PM

No, but close enough.

For example, if you hold a reference to a game object or a component attached to it and destroy the object, those references turn into null, where inactive game objects just don't execute any code from the engine. You may still call functions on any attached scripts.

As long as you are aware of t$$anonymous$$s difference, it is just about the same, and I believe it is a good approach on reducing overhead. I ain't truthfully sure.

  • How much performance you gain or lose, you have to test for yourself.
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
5

Answer by bcedmark · Aug 17, 2011 at 03:18 AM

The differences between an active GameObject and an inactive GameObject are:

  1. The inactive GameObject's attached MonoBehaviours won't receive most Unity messages. T$$anonymous$$s includes update calls (FixedUpdate, LateUpdate, Update) and any messages sent by SendMessage or BroadcastMessage.

  2. An inactive GameObject won't interact with physics.

  3. An inactive GameObject won't show up in the array returned by Object.FindObjectsOfType(GameObject).

You can still directly reference an inactive GameObject, as Statement mentioned, and you can directly call methods on it and its components. You could even directly call Unity message methods if they're public, though that might get confusing. In summary, the difference between inactive and destroyed is the difference between $$anonymous$$ding your computer in a closet with spotty Internet access and chucking it into a black hole.

GameObject.active isn't the quickest property on Earth, but setting it should be much faster than Destroying and Instantiating a new GameObject, and it won't waste any memory (unless you use SetActiveRecursively, w$$anonymous$$ch consumes a tiny bit of memory to get the enumeration it iterates over.)

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
1

Answer by Johan 4 · Apr 17, 2011 at 03:49 PM

Most of the time they are the same. When you disable an object, it is "removed" and to place it back in takes same time as instantiating a new one.

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.

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

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

C# iOS - .active, SetActive(false) 0 Answers

Have a spawning issue on iOS 0 Answers

AssetBundle instantiation in android/ios 0 Answers

Generate a continuos platform for endless runner 3 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