Skip to content

Add Lifecycle generator; Singleton/Dependency stop owning Awake/Start#9

Merged
migus88 merged 4 commits into
mainfrom
feat/lifecycle-generator
May 30, 2026
Merged

Add Lifecycle generator; Singleton/Dependency stop owning Awake/Start#9
migus88 merged 4 commits into
mainfrom
feat/lifecycle-generator

Conversation

@migus88

@migus88 migus88 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New [Awake] / [Start] / [OnEnable] / [OnDisable] / [Update] / [FixedUpdate] / [LateUpdate] / [OnDestroy] attributes mark MonoBehaviour methods that the new LifecycleGenerator invokes from a single dispatcher per phase. Optional int order argument sorts methods (source order on tie); the analyzer warns on duplicate explicit orders.
  • [Singleton] and [Dependency] no longer emit Awake() / Start() directly. They emit private bool SingletonAwake() and private void DependencyStart() helpers that the lifecycle dispatcher calls first. The Singleton helper returns false on a duplicate (after Destroy(gameObject)) so the dispatcher short-circuits before any user [Awake] / OnAwake runs on the doomed instance.
  • Back-compat preserved: the Awake and Start dispatchers still call and declare the OnAwake() / OnStart() partial hooks, so existing code keeps working unchanged.

Test plan

  • dotnet build src/generators-src/EngineRoom.Generators.sln -c Release — clean
  • PlayMode tests in Unity 6000.4.0f1: new EngineRoom.Demo.Lifecycle.Tests (7 cases covering one-shot callbacks, Update/LateUpdate/FixedUpdate cadence, explicit ordering, Singleton+Awake interaction, duplicate-singleton short-circuit) + existing EngineRoom.Demo.Singletons.Tests — all green
  • Open tests/generators-tests-2022-3-62/ in Unity 2022.3.62 and confirm package still loads
  • Spot-check the new ERG0203 message by adding void Awake() {} to a [Singleton] class — it should suggest marking a method with [Awake]

migus88 added 4 commits May 30, 2026 17:44
Events were silently dropped by the formatter and by the auto-include
candidate check, so a public event on a [Singleton] class never appeared
on its generated interface. Format IEventSymbol as `event Type Name;`,
accept events in auto-mode, widen [SingletonInclude] / [SingletonIgnore]
to AttributeTargets.Event, and add a demo CountChanged event with a test
that subscribes through the interface.
The tests exercise [Dependency] resolution and the singleton lifecycle,
which only run in PlayMode. Drop the EditMode-only test runner reference
and Editor platform restriction so the [UnityTest] coroutines that yield
a frame for Start() can run.
… owning Awake/Start

New [Awake]/[Start]/[OnEnable]/[OnDisable]/[Update]/[FixedUpdate]/[LateUpdate]/[OnDestroy] attributes mark
MonoBehaviour methods to be invoked from a single generated dispatcher per lifecycle
phase, ordered by an optional int Order arg (source order on tie). [Singleton] and
[Dependency] now contribute private SingletonAwake()/DependencyStart() helpers
instead of owning Awake/Start themselves, so multiple features can cooperate on the
same MonoBehaviour without colliding. The Singleton helper returns false on a
duplicate (after Destroy) so the dispatcher short-circuits before any user [Awake]
or OnAwake runs on the doomed instance.

Backwards-compatible: the Awake/Start dispatchers still call (and declare) the
OnAwake()/OnStart() partial hooks. ERG0003/ERG0103 retired in favor of the
unified ERG0203, which suggests adding a [Awake]/[Start]/etc. method.
# Conflicts:
#	src/generators-unity/Packages/games.engine-room.generators/Runtime/Plugins/EngineRoom.Generators.dll
@migus88 migus88 merged commit 9dbb810 into main May 30, 2026
@migus88 migus88 deleted the feat/lifecycle-generator branch May 30, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant