Choose the initialization difference between awake and start

Source: Internet
Author: User

Origin: In a hurry to find unity work, the Examiner asked me generally write initialization value, you write in that method inside!
My heart always appeared awake and start, so I want to say awake method. But I can't read .... I asked him if he could write it.
He still agreed to my request, I was happy to write to him on the paper. After a round of discussion he told me to go home and wait for notice.

Premise: do not talk about the awake method can mediate his execution time!

Gameobject is a tree structure, from top to bottom, from the root of the component awake method to execute down, and then the same way to execute the Start method. Not a Awake,start method that executes a awake,start executing another component

Conclusion:
1.1 Gameobject do not need other Gameobject above the component properties to initialize, you choose Awake or Start is not a problem.
(Preferred awake, write this code component in awake ().  Enable = false; Start can be paused.)

2. The components on the two gameobject (A, B) A is the parent node of B, A is a component, and a requires a property of reference B to initialize
A is initialized in awake, B is initialized in awake. Error
A at start initialization, B is initialized at start. Error
A at start initialization, B is initialized in awake. Success


3. Components to their own property initialization, must be in awake (), need to call other components to initialize or complete a behavior, should be written in the start ()


Several property initialization options:
attribute = new class name (); Often dry
The construction method has never seen it do this.
Awake () method often dry
Start () method often dry

Choose the initialization difference between awake and start

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.