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
1
Question by Paulius-Liekis · Sep 21, 2015 at 09:41 AM · monobehaviourawakeload levelscript execution order

Is there a method on MonoBehaviour that is called on load even if GameObject is disabled?

I need to get a notification that script was loaded even if GameObject is disabled in hierarchy. I though Awake does that, but it isn't called until GameObject is activated.

Is there such method?

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 Nerevar · Sep 21, 2015 at 02:00 PM 0
Share

Hello,

I don't think there is any method for that, why would you need this exactly? there might be a way around your problem...

3 Replies

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

Answer by Hellium · Sep 21, 2015 at 02:17 PM

If you read the manual : http://docs.unity3d.com/Manual/ExecutionOrder.html

You will see that there is no method before Awake (except Reset) that is called if the GameObject is disabled.

A workaround would be : Enable the object in the hierarchy, and disable it in the Awake function. Thus, the start, Update, .... won't be called.

Comment
Add comment · Show 1 · 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 Ziplock9000 · Jan 11, 2021 at 04:24 AM -1
Share

That's a terrible hack that reduces performance, increases memory load and bad program$$anonymous$$g.

avatar image
1

Answer by amanpu · Sep 21, 2015 at 02:44 PM

@Hellium's answer is correct that there is no method which is invoked if gameobject is disabled in hierarchy , you need to disable gameobject in Awake().

Along with it you should also change Script Execution Order so that your this script is called before all other scripts and does not effecting execution of other script.

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 Xtro · Dec 03, 2016 at 10:29 PM

It's very strange that Unity team never needed to create this feature. It is a must for programming.

Anyways, I created this asset for this purpose!

https://www.assetstore.unity3d.com/en/#!/content/23453

Comment
Add comment · Show 3 · 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 Ziplock9000 · Jan 11, 2021 at 04:25 AM 0
Share

I agree it is a must, it's essentially a constructor that is safe for unity.

avatar image Bunny83 Ziplock9000 · Jan 11, 2021 at 08:42 AM -1
Share

It'S not really a must. You just have the wrong idea about gameobject usage. GameObjects that are deactivated are essentially not present for Unity. There should be no need for code to run on such gameobjects. The only reason would be that you access this object from the outside and use it from an active object. So you are violating this concept. If you want to work with a gameobject it should be active. If you need a specific behaviour of the gameobject you attach "behaviours" aka components to dictate its behaviour.


Don't get me wrong, sure a callback would be neat for some cases, however it's not really necessary. If you have a concrete issue that you can not solve without such a method, feel free to create your own question and we can give some recommendations how you can solve it. When you run into an issue with the world you should not expect the world to change but you should consider how you can adapt to the world. There is no perfectly designed API in this world. Complaining on a Q&A site about the current implementation does not bring you closer to a solution.

avatar image Ziplock9000 Bunny83 · Jan 11, 2021 at 05:27 PM 1
Share

No it's not a must. You're quoting limitations of gameobjects, not of what is possible with program$$anonymous$$g, which is what the OP is asking. $$anonymous$$ove along if you're not able to provide an answer.

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

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

Related Questions

singleton becomes null? 0 Answers

Can't use Script Execution Order 1 Answer

Update and Awake not being called. 1 Answer

How to mock or skip execution of Awake in playmode unit tests? 2 Answers

Component's Start/Awake methods not being called 2 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