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
2
Question by Rotary-Heart · Dec 12, 2014 at 04:37 AM · gameobjectscene-loading

Inactive GameObject at start of scene

If I have a GameObject that its invective by default. When I start the game/scene, Does the scripts get called? Does unity load it and then set it inactive?

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
-2
Best Answer

Answer by fafase · Dec 12, 2014 at 07:54 PM

yes it does. the awake is called regardless the state. Start is called on first run, OnEnable any time you switch on or off Some of the callbacks are waiting on the events and will be called regardless the state. Drawing and setting off is no solution since drawing is performed after all updates and if set off it won't draw.

Waiting time on start is no real issue so create them all at the beginning and put a loading screen to hide.

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 Rotary-Heart · Dec 12, 2014 at 08:03 PM 0
Share

I'm trying to understand what is the advantage of setting it inactive in the editor. Let's say that I want to publish my scene with half of the 3D models active. Will it take the same time to load the scene if they all where active?

avatar image NicRule · Dec 12, 2014 at 08:16 PM 0
Share

Load time is not as important as framerate. Performance (framerate) is hurt by what is active and unaffected by what's hidden. You keep asking about load time which is when objects are initialized and only happens once each scene. Open Unity, load in about a thousand objects, parent them to something, and test the load and run times with it hidden and viable. just testing it yourself is often the most accurate answere.

avatar image Rotary-Heart · Dec 12, 2014 at 08:20 PM 0
Share

I know that it happens once, that's exactly why I'm asking this. Let me try to explain better, if I have a scene with a 100 heavy 3D models that are set to inactive in the editor. When I open/run my scene does Unity loads them even if they are inactive? Or Unity ignores them until I set them to active with a script?

avatar image NicRule · Dec 12, 2014 at 08:45 PM 0
Share

I just tested it with some massive meshes. With them visible it took 3.2 seconds to load. With them hidden 2 seconds. With them deleted it loaded in 1.1 seconds. That's the practical answer. I don't know what Unity does behind the scenes.

avatar image
5

Answer by NicRule · Dec 12, 2014 at 04:47 AM

If it is set inactive in the editor the scripts attached to it will not run. It will use the Awake() and Start() function only the first time it is activated, regardless of when this happens. If it is set inactive by its own script, it will run only to that point.

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 Rotary-Heart · Dec 12, 2014 at 04:51 AM 0
Share

So, if I have like 100 GameObjects (its just an example) full of heavy 3D models but they all are inactive my scene should run/open fast because they are not active?

avatar image NicRule · Dec 12, 2014 at 06:14 PM 0
Share

I just tested it and it takes about the same time to load even if the objects are turned off. It will take slightly less time but it still has to process a lot of objects.

avatar image Rotary-Heart · Dec 12, 2014 at 06:18 PM 0
Share

Like if it draws them and then hides them?

avatar image NicRule · Dec 12, 2014 at 07:47 PM 0
Share

Drawing then hiding is less efficient because it has to go through the process of hiding each object.

avatar image
0

Answer by MOTYSHIZ · Jul 01, 2016 at 06:04 AM

I have Just tested this, and it seems that the scripts are not called on an inactive object. Awake() will be called if the script is inactive, not the GameObject holding the script.

This is evident in this short example: https://unity3d.com/learn/tutorials/topics/scripting/awake-and-start

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

27 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 avatar image avatar image

Related Questions

Asset Bundle starts loaded 0 Answers

Loading a level and getting all new gameobjects 1 Answer

How to destroy a gameobject on collision and keep it dead on reload of the scene? 1 Answer

survival shooter game restarting when player dies 2 Answers

Objects are destroyed/disfunctional after changing scene 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