#When do Awake and Start get called after AddComponent or Instantiate?
1 messages · Page 1 of 1 (latest)
Well you can't add a component to an Object before it has been instantiated,
Once the component is added, the very first time you ever access the class, is when it's Awake gets called
No, it's not. Unity objects and components are initialized at a very specific time in a frame.
Pretty sure awake and on enable are called immediately during the add component call. Regarding start, not sure, it could be immediate as well, or at the start of the next frame. Anyways, before the first update is called on the object.
https://docs.unity3d.com/6000.2/Documentation/Manual/event-functions.html#initialization-events
You could test it yourself by adding logs in different events and see what order they are logged in.
When you add a component as part of instantiation of a a disabled object, awake and start are not called. When you enable that object, Awake gets called immediately when you do that. Start is called in the next frame the object is active. if you add a component on an activated object, awake is called immediately and start in the next frame the object is active. It depends on when you call AddComponent whether 'next frame' is the current one, or the actually next one. Its a good practice to avoid code that depends on fine grained control of these things during regular game logic. If you need detailed control and possibly more of these callbacks (custom ones) you can make your own set by using the trickery described above + a custom orchestrator.
I see, thanks a lot :)
Also thanks for your insight