Skip to content

Fix: use DestroyImmediate when disposing LifetimeScope outside Play Mode - #861

Open
Acharad wants to merge 1 commit into
hadashiA:masterfrom
Acharad:fix/814-editor-destroy
Open

Fix: use DestroyImmediate when disposing LifetimeScope outside Play Mode#861
Acharad wants to merge 1 commit into
hadashiA:masterfrom
Acharad:fix/814-editor-destroy

Conversation

@Acharad

@Acharad Acharad commented Jul 17, 2026

Copy link
Copy Markdown

Fixes #814

Hit the same issue @Nitero described in #814 — calling Dispose() on
a LifetimeScope outside Play Mode throws, because it always calls
Destroy(), which only works while the game is actually running. Ran
into this myself while writing an Editor test, and figured I'd fix it
properly instead of working around it locally.

Dispose() now checks Application.isPlaying and calls
DestroyImmediate(gameObject) when it's false. Play Mode behavior
(Destroy) is unchanged.

Didn't add an automated test — this repo's only test assembly
(VContainer.Tests.asmdef) isn't restricted to the Editor platform,
so Unity runs it under PlayMode, where Application.isPlaying is
always true and this branch would never actually be exercised.
Verified manually instead. Happy to add a proper Editor-only test
assembly in a follow-up if that'd be useful.

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

@Acharad is attempting to deploy a commit to the hadashia's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Destroy LifetimeScope in Editor

1 participant