"Go" to figure out how these functions are called in the script.

Source: Internet
Author: User

I didn't verify it! ~~~~~

Please poke: Figure out how these functions are called in the script

Call to start and awake functions when the game object is active or if the script is enabled
There are basically four scenarios:
1.game object is active but script is disabled
At this point, only the awake function is called immediately when the object is created, and onenable and Start are called after the enabled script.
2.game object is deactive but script is enabled
At this point, when the object is created, no function is called, and the function is called after the active object in awake onenable Start order.
3.game object is avtive and script is enabled
At this point, when the object is created, it executes the function in Awake onenable start order.
The 4.game object is deactive and the script is disabled
There is no function call to create the object at this time, and the awake function is called immediately after the active object, and onenable and start are then called after the enabled script.

It is important to note that awake and start are called only once in the life cycle of a game object, but Onenable is executed again every time the script is activated.
If you create an object in the game and activate its script, then awake onenable Start will be called, and a script with the enabled set to False will ondisable be called
, Onenable will be called again when it is activated again awake and Start will not be called again. Note When a game object is setactive (false), its binding script and ondisable in the sub-script are also
will be called, SetActive (True) when the onenable is called. This can explain why you would write code in their onenable and ondisable OnDestroy when subscribing to and removing event delegates for a game object.
, I did not understand this before.

"Go" to figure out how these functions are called in the script.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.