Fixed prefab instantiation with Configurable Enter Play Mode #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for sending a pull request! Please make sure you read the contribution guidelines
Pull request checklist
Please check if your PR fulfills the following requirements:
Pull request type
Please check the type of change your PR introduces:
Issue Number
Issue Number: N/A
Create or search an issue here: Extenject/Issues
What is the current behavior?
We encountered an issue where ZenjectIntegrationTestFixture destroys MainThreadDispatcher before ProjectContext, which leads to test failures when MainThreadDispatcher is used when disposing the context. This happens when Unity is configured to enter/exit play mode without a domain reload.
Under the hood a magical
_disabledIndestructibleGameObject
is used in the Unity Editor to instantiate prefabs in an inactive state. ProjectContext is one such prefab. The reference to this magical GameObject is stored in a static variable:After exiting play mode, this GameObject reference is still alive (null check returns false). The GameObject ends up in an unloaded scene named "null". Unity will happily instantiate prefabs into this null state.
When running a test that inherits from ZenjectIntegrationTestFixture, the hierarchy of the
DontDestroyOnLoad
scene will be incorrect, resulting in ProjectContext getting destroyed too early.The issue is resolved when I trigger a domain reload by modifying a script, but returns when I enter and exit play mode again.
What is the new behavior?
After exiting play mode, a new GameObject will be created. ProjectContext and other prefabs will always be instantiated in the correct place (the
DontDestroyOnLoad
scene).Does this introduce a breaking change?
Other information
On which Unity version has this been tested?
Scripting backend: