Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed prefab instantiation with Configurable Enter Play Mode #26

Merged
merged 1 commit into from
Feb 16, 2022

Conversation

Nezz
Copy link

@Nezz Nezz commented Feb 10, 2022

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:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • No compiler errors or warnings

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

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:

static GameObject _disabledIndestructibleGameObject;

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?

  • Yes
  • No

Other information

  • This change only effects the behaviour in the Unity Editor.

On which Unity version has this been tested?

  • 2020.3 LTS
  • 2020.2
  • 2020.1
  • 2019.4 LTS
  • 2019.3
  • 2019.2
  • 2019.1
  • 2018.4 LTS

Scripting backend:

  • Mono
  • IL2CPP

Note: Every pull request is tested on the Continuous Integration (CI) system to confirm that it works in Unity.

Ideally, the pull request will pass ("be green"). This means that all tests pass and there are no errors. However, it is not uncommon for the CI infrastructure itself to fail on specific platforms or for so-called "flaky" tests to fail ("be red"). Each CI failure must be manually inspected to determine the cause.

CI starts automatically when you open a pull request, but only Releasers/Collaborators can restart a CI run. If you believe CI is giving a false negative, ask a Releaser to restart the tests.

@Mathijs-Bakker Mathijs-Bakker merged commit 7ba9fcf into Mathijs-Bakker:master Feb 16, 2022
@Nezz Nezz deleted the patch-1 branch February 18, 2022 13:30
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.

2 participants