Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
0
Found in
2020.3.43f1
2021.3.16f1
2022.2.2f1
2023.1.0a24
Issue ID
UUM-21741
Regression
No
Prefab modification is not detected when adding a new array element
How to reproduce:
1. Open the user’s attached “Prefab Change Detection But.zip” project
2. Add “Prefab” Prefab to the Hierarchy and observe the data array in the Inspector
3. Press the “Change Data” button and observe the data array
4. Enter Play Mode and observe the data array in the Inspector
Expected result: Newly added array element is detected as a prefab modification
Actual result: Newly added array element is not detected as a prefab modification
Reproducible with: 2020.3.43f1, 2021.3.16f1, 2022.2.2f1, 2023.1.0a24
Reproduced on: macOS 12.4 (Intel)
Note: After the 3rd step a new array element is added with a value “9” but it’s not detected as a prefab modification so its value is changed to “0” after entering Play Mode
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
- "Microsoft Visual Studio Community" module appears checked in Add modules when it was not installed
- Editor window is not opened when launching the project with 2021 or 2022 streams
- Any Unity Editor version is not uninstalled when trying to uninstall it through Unity Hub
- "Trying to access the DPI setting of a visual element that is not on a panel." warning thrown when entering/exiting Play Mode with new Hierarchy not displayed
- Transparent geometry does not render in Built-in Renderer Deferred mode when a custom post-processing effect is enabled on Mac with Metal API
Resolution Note:
Note that you need to use RecordPrefabInstancePropertyModifications() when editing properties directly instead of using SerializedProperty. Check the docs for for an example:
https://docs.unity3d.com/ScriptReference/PrefabUtility.RecordPrefabInstancePropertyModifications.html
[CustomEditor(typeof(NewBehaviourScript))]
public class NewBehaviourScriptEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Change Data"))
{
var target = (NewBehaviourScript)this.target;
Undo.RecordObject(target, "Change Data");
target.data = new float[] { 0, 1, 2, 3, 4, 9999, 5, 6, 7, 8, 9 };
PrefabUtility.RecordPrefabInstancePropertyModifications(target); // <--- you need this
}
}
}
Resolution Note (2023.1.X):
Note that you need to use RecordPrefabInstancePropertyModifications() when editing properties directly instead of using SerializedProperty. Check the docs for for an example:
https://docs.unity3d.com/ScriptReference/PrefabUtility.RecordPrefabInstancePropertyModifications.html
[CustomEditor(typeof(NewBehaviourScript))]
public class NewBehaviourScriptEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Change Data"))
{
var target = (NewBehaviourScript)this.target;
Undo.RecordObject(target, "Change Data");
target.data = new float[] { 0, 1, 2, 3, 4, 9999, 5, 6, 7, 8, 9 };
PrefabUtility.RecordPrefabInstancePropertyModifications(target); // <--- you need this
}
}
}