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
- ":focus" style will not be shown when the UI element is unparented and reparented and the "Focus()" method is called without the "Blur()" method being called
- Crash on BucketAllocator::Allocate when importing TextMeshPro assets
- Playmode dropdown creates continuous "Layout update is struggling" errors at certain aspect ratios
- Editor takes a long time to open VFX Graph 'Subgraph' asset when it is heavily referenced by multiple other VFX Graphs
- "Editor Event Handler Error" error is thrown when using Terrain Tool shortcuts
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.