Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2019.4.16f1
2020.3
2021.1
2021.2
2022.1
Issue ID
1368047
Regression
No
EditorApplication.playModeStateChanged event is inaccurate when raised from Prefab script
How to reproduce:
1. Open the user's attached project
2. Open scene Scenes/SampleScene
3. Press the Play button
4. Observe the Console
Expected result: the load times logged to the Console from the two GameObjects are the same
Actual result: the load time logged from the Prefab is incorrect
Reproducible with: 2019.4.31f1, 2020.3.21f1, 2021.1.26f1, 2021.2.0b16, 2022.1.0a12
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
- Tile Palette selected dropdown text does not update when palette is renamed
- ArgumentException thrown and reference to Template gets unset when opening UXML file after editing referenced Template in Play mode
- [iOS][WebGL] Player freezes when multiple properties of a VisualElement are changed at the same time
- Warning 'GetControlID at event ValidateCommand returns a controlID different from the one in the Layout event' is logged when undoing the deletion of an Edited Freeform 2D Light
- ShadowCaster2D breaks on certain Rotation positions when Casting Source is set to PolygonCollider2D
Resolution Note:
When changing a property on a Prefab instance from script it is important to get it recorded as an override. Otherwise it will not be persisted. And that is the problem happening here: when entering Playmode the scene is reloaded and will lose its changes because RecordPrefabInstancePropertyModifications was not called. To fix this issue in the repro project do this:
private void OnPlayModeChanged(PlayModeStateChange stateChange) {
switch (stateChange) {
case PlayModeStateChange.ExitingEditMode:
playButtonTime = DateTime.Now.Ticks;
PrefabUtility.RecordPrefabInstancePropertyModifications(this); <--- ADD THIS