Per-frame lifecycle: Update, FixedUpdate, Start, OnDestroy and Time (#81) #93
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
crowmaki/cinnabar!93
Loading…
Reference in a new issue
No description provided.
Delete branch "issue-81-script-lifecycle"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #81. Part of #75.
What
A Script Component's
Update(dt),FixedUpdate(dt),Start()andOnDestroy()run from the Plugin's Hooks and the Schema's Component Hooks.updateandfixed_updatewalk each Script class in Schema registration order and, within a class, walkcomponent_storageby index, re-fetching storage every iteration. Instances on a GameObject that is not Active in Hierarchy, and instances already queued for removal, are skipped.Startruns once per instance, immediately before its first frame method, behind a TransientBoolfield the Plugin appends to every Script Schema. Its name is@started, which no Luau identifier can spell, so it never collides with a Script's own fields and never reaches a Scene Document.OnDestroyruns fromon_remove, so it runs exactly once whether the Component was removed directly, its owner destroyed, or its Scene unloaded.Timeglobal carriesdeltaTime,fixedDeltaTimeandframeCount, refreshed at the top of each Hook from Frame Timing. InsideFixedUpdate,deltaTimeis the fixed step, the Unity way.pcallwith a traceback handler. An error in one instance is logged and the rest of the frame continues.Component_Field_Descgainsflags, so a description can mark a field Transient. The struct stays 16 bytes.One reading to confirm:
Startruns before whichever ofFixedUpdateorUpdatefirst reaches the instance in a Tick, which is Unity's ordering. The issue text names onlyUpdate.Tests
tests/luau/lifecycle_test.odincovers every acceptance criterion from Luau source strings.tests/core/component_schema_test.odincovers the Transient flag on a description field.The luau harness had a bug:
capture_loggerreplaced the runner's logger, so no luau test could fail. It now forwards lines logged from_test.odinfiles to the runner. Every prior test still passes.just checkandjust testpass (430 tests).