Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by spritesobhan · Apr 30, 2017 at 10:19 AM · gameobjectscripting beginnerstartawakeonenable

If a script is attached to more than one gameObject, will Start() & Awake() run more than once?

The same script. Different gameObjects disabled at runtime. Enabled at different time periods throughout the game.

Will Start() & Awake() run for each gameObject becoming enabled?

Or do I need to use OnEnable()?

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 Sergio7888 · Apr 28, 2017 at 11:03 PM 0
Share

Start and Awake will run "only once" for each script instance, OnEnable will run "every time" the script become enabled.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bodrp · Apr 30, 2017 at 01:50 PM

Start() and Awake() will be called when the component becomes active for the first time only. They will act on their own instance of the component (since they are not static methods). OnEnable() gets called everytime the component becomes active. By "acting on their own instance" I mean that for every instance of the component, they will be called and will have access to their instance's attributes, whatever may be their access level.

Awake() will be called first, then OnEnable(), then Start(). If multiple components are activated at the same time, Awake() and OnEnable() methods will be called jointly for each instance. When that's done, each instance's Start() method will be called.

For more information about the methods Unity calls with reflection on your components, you can refer to the execution order page of the manual.

Comment
Add comment · Show 2 · 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 hexagonius · May 01, 2017 at 08:21 AM 1
Share

A little correction on the order of Awake and OnEnable. They alternate. Each Awake is directly followed by its OnEnable

avatar image Bodrp hexagonius · May 02, 2017 at 12:22 AM 0
Share

Thank you! I am fixing it right now.

avatar image
0

Answer by hexagonius · Apr 30, 2017 at 12:16 PM

Short answer is yes, both will run on each. AmEnable would be ran every time the script/ gameobject is toggled

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

6 People are following this question.

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

Related Questions

Execution Order of Scripts - Awake and OnEnable 1 Answer

Does the access modifier of Start(), Awake(), OnEnable() make a difference to Unity? 3 Answers

Should OnEnabled() be changed to be called after Start()? 1 Answer

OnEnable, Awake, Start order 8 Answers

AddComponent passing variable before Start/Awake 5 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