Tuesday, July 22, 2014

Unity3d Important Methods and its Priority Order

Some Unity3d important methods and its usage with priority order,

[1] Awake : 

        Called just after object got initialized, also for prefab. It is called before Start function call. If gameobject is disabled Awake is not called, but if any function of this script or function of script attached to same object is invoked, object would be initialized and Awake is called. This is where most of developers got confused with Awake method invocation.
Priority : 1


[2] OnEnable : 

        This is called when Monobehaviour is enabled. It is also called before Start call. If object is not active this will not be invoked.
Priority : 2


[3] Start :

        Start is called before any frame update started if object is enabled.
Priority : 3

[4] FixedUndate :

        Fixed update is called more frequently then Update call if frame rate is low. If frame rate is high then it might called less frequently then Update call. Fixed update is called on reliable basis then Update function that's why you do not need to multiply movement calculation with Time.deltaTime. All physics related calculation should be placed inside FixedUpdate to make it behave correctly.
Priority : 4


[5] Update : 

        Update is called once per frame. This is main function in Unity3d Monobehaviour. If frame rate is set to be high then all input related code should be placed here to avoid input issues.
Priority : 5


[6] LateUpdate :

        LateUpdate is also called once per frame. The only difference between Update and LateUpdate is that its been called once Update has completed its execution. This will be very usefull in case where there is a need of task to be executed if and only if another task got completed. 
Example : Camera movement, score calculation, input management.
Priority : 6


[7] OnDisable : 

        This is called when Monobehaviour becomes inactive/disabled.
Priority : 7


[8] OnGUI :

        This function is called multiple time per frame, might call double then the Update call depending upon current frame rate. All input related code should be place in this function. Main use of this function is two draw various UI elements. Thought it is not advisable to use this function as of performance issues.

No comments:

Post a Comment

Popular Posts