+ 3

methods in unity

For Initiating: Awake() Start() 1.Why do we have two initiation methods? 2.What are the differences? 3.What are the best practices when using them? For Updating: Update() FixedUpdate() LateUpdate() 1.Why three different update methods? 2.What are the differences? 3.and some best practices?

27th Jul 2017, 3:12 PM
AryaJ
AryaJ - avatar
3 Antworten
+ 3
Finally another Unity question! 😀 Awake is called once before Start. Essentially when the scene is loaded. Start is called once before the first frame is updated. So, right before update will be called. I'd say use Awake() for initializing the current objects components (Like a constructor) and Start() for using them. (When you want something to be called once before anything else) Update is called every frame. This is the general thing you will mostly use. FixedUpdate is called on par with the physics. Every time the physics is calculated, fixedUpdate is called. This time will always be constant. Use this when handling physics. This can be faster or slower than Update(), depending on the frame rate of Update. I think by default it is called every 0.02s. Things like RigidBodies use Physics (So use FixedUpdate for those). LateUpdate is called when Update is finished. Quoted from Unity docs: "A common use for LateUpdate would be a following third-person camera. If you make your character move and turn inside Update, you can perform all camera movement and rotation calculations in LateUpdate. This will ensure that the character has moved completely before the camera tracks its position"
27th Jul 2017, 3:24 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
i'm still confusing about update(), what the frame is it?
27th Jul 2017, 3:30 PM
AryaJ
AryaJ - avatar
+ 1
Update() runs every frame. What the frame rate is depends on your computer and the performance of the game. When I said "called" I meant run. As if Unity does: myObject.Update();
27th Jul 2017, 3:42 PM
Rrestoring faith
Rrestoring faith - avatar