The manual section on Application lifecycle - The update loop is missing certain steps, and the order of operations appears to be described incorrectly in the page text.
The following description is based on this repro case project: https://github.com/redoak/defold-message-dispatch-order
I have this simple structure in the project.
main collection:
go: script
go: gui + gui_script
go: collectionproxy + script
go: script
go: gui + gui_script
Each script and gui_script implements init
, final
, update
, fixed_update
(only in script), on_message
, and on_input
. Each function posts a message to "#"
in order to see when the message is dispatched and handled. I didn't implement `fixed_update for gui_script, since I suspect that's not supposed to be supported (see #8524).
This is the order of operations I see, with Defold version 1.6.3:
main: script and gui_script init
main: message dispatch
proxy: script and gui_script init
proxy: message dispatch
main: script + gui_script on_input
proxy: script + gui_script on_input
proxy: message dispatch
proxy: script update
proxy: message dispatch
proxy: gui_script update
proxy: message dispatch
proxy: script fixed_update
proxy: message dispatch
main: message dispatch
main: script update
main: message dispatch
main: gui_script update
main: message dispatch
main: script fixed_update
main: message dispatch
proxy: script + gui_script final
proxy: message dispatch
main: script + gui_script final
main: message dispatch
Interestingly, even though I load, init and enable the collectionproxy during init, no input will be passed on to the proxy on the first frame. It seems like a bug to me, but I don't know. Either way, it's unlikely to ever really matter.
Manual inaccuracies:
- The message dispatch between
on_input
and update
is not shown in the graphic or mentioned under Input.
- The Input and Update description makes it sound like the sequence should be main on_input, proxy on_input, main update, proxy update. As seen above, this is not the case, and instead all the proxy functions are called in one go after main's on_input.
- The Update description also suggests that script update, script fixed_update, and gui_script update will all be called before a message dispatch. This is not the case as seen above.
I haven't looked at when these are received/called:
- collectionfactory: load callback
- collectionproxy: proxy_loaded async, proxy_unloaded
- gui_script: layout_changed
- http: request callback
- liveupdate: store_resource callback, store_manifest callback, store_archive callback, add_mount callback
- model: model_animation_done, play_anim callback
- render_script: window_resized, set_view_projection
- particlefx: play callback
- physics: collision_response, contact_point_response, trigger_response, ray_cast_response, ray_cast_missed
- sound: sound_done, sound_stopped, play callback
- sprite: animation_done
- timer: delay callback, trigger
- window: set_listener
On a side note, to make the three images on the page easier to edit, and make their content show up in searches, perhaps they could be replaced with text. It would be fairly easy to recreate the same 3-column layout with markup tables (if that's desired). If you want to keep the iconography, and you are able to display emojis, you can use emojis such as ✉️ and 🏭.