Search Issue Tracker
By Design
Unknown (hidden) 2020.3.X, 2021.3.X, 2022.1.X, 2022.2.X, 2023.1.X
Votes
0
Found in
2020.3.39f1
2021.3.9f1
2022.1.16f1
2022.2.0b7
2023.1.0a9
Issue ID
UUM-13496
Regression
No
Variable values in script are not updated after entering Play Mode for first time
How to reproduce:
1. Open attached project
2. In Editor open any Scene (e.g. Assets/Scenes/GameScene)
3. Create any object in Hierarchy (e.g. Cube)
4. Create empty script on new Cube object
5. Open created script
6. In script declare variable with some value:
Example:
{code:java}
private int testVariable = 99;
{code}
7. In Start method print out variable:
Example:
{code:java}
void Start()
{
Debug.Log(testVariable);
}
{code}
8. In Editor enter Play mode and check Console for the printed value
9. Exit Play mode
10. Go back to the script and change value to something else
Example:
{code:java}
private int testVariable = 55;
{code}
11. Wait for recompile to complete
12. In Editor enter Play mode and check Console for the printed value
13. Exit Play mode
14. In Editor Enter play mode again and check Console for the value
Expected results: Variable value printed in console matches the one in the script when entering Play mode for first time.
Actual results: Old variable value is printed when entering Play mode the first time. It is only updated after entering Play mode the second time.
Reproducible on all latest streams 2020.3.39f1, 2021.3.9f1, 2022.1.16f1, 2022.2.0b7, 2023.1.0a9.
Notes:
- Tested on Win11
- Unable to reproduce on fresh/empty project
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Resolution Note:
This is by design to support hot-reloading https://docs.unity3d.com/Manual/script-Serialization.html. If you want the behaviour you are intending, this could be achieved by adding [System.NonSerialized] attribute to the field.