Search Issue Tracker
By Design
By Design in 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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
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.
Resolution Note (2023.1.X):
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.