Search Issue Tracker

By Design

Votes

0

Found in

2022.3.29f1

6000.0.2f1

Issue ID

UUM-72216

Regression

No

Private field value assignment via Script is not applied when you enter the Play Mode for the first time after the change

--

-

How to reproduce:
1. Open the user-attached project “TEST”
2. Open the “SampleScene” scene
3. Open the “TEST.cs” Script asset
4. In line 8 change the “gla” variable value from “false” to “true”
5. Save the Script and enter the Play Mode
6. Observe the Console

Expected results: “true” is logged into the Console
Actual results: “false” is logged into the Console

Reproducible with: 2022.3.29f1, 6000.0.2f1
Can’t test with: 2021.3.38f1 (Script can’t be loaded with no errors at all)

Reproducible on: Windows 11 Pro
Not reproducible on: No other environment tested

Note:
-The correct value is logged the second time you enter the Play Mode
-After the change Unity indicates Script recompiling

  1. Resolution Note:

    This behaviour is by design: the init value from the script is used at creation time of the MonoBehaviour component. Even though after the script change we do reload the scripts, the preexisting MonoBehaviour was not created after the script reload so the new value is not relevant. The non-static private field is backed up and restored during the code reload as is and will remain the same, even though a new MonoBehaviour created post-reload will get a different value through the updated init script line. To avoid that, please set 'When entering Play Mode' setting to 'Reload Domain and Scene' or 'Reload Scene only'.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.