Commit 7aa10e2
Improve play mode test detection by preventing RuntimeInitializeOnLoadMethod registration
The previous fix checked TestRunnerCallbacks.IsRunningTests at runtime, but there was a
timing issue - RuntimeInitializeOnLoadMethod executes before TestRunnerCallbacks.RunStarted
is called, so the flag was not set yet.
This commit uses the cleaner approach recommended by Unity: prevent the method from being
registered at all during tests by applying #if !UNITY_INCLUDE_TESTS to the attribute itself.
This eliminates the runtime check and TestRunnerCallbacks dependency entirely from
ChangeScene.cs, making the code simpler and more reliable.
References:
- Unity Discussions: RuntimeInitializeOnLoadMethod runs during playmode unit tests
https://discussions.unity.com/t/methods-with-runtimeinitializeonloadmethod-attribute-run-during-playmode-unit-tests/949876
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 32a7722 commit 7aa10e2
1 file changed
Lines changed: 3 additions & 8 deletions
Lines changed: 3 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 18 | | |
24 | 19 | | |
25 | 20 | | |
| |||
0 commit comments