Search Issue Tracker

By Design

Votes

0

Found in

2018.4

2019.4

2020.2

2020.2.6f1

2021.1

2021.2

Issue ID

1318195

Regression

No

Can't override prefab's Script component's value ​​by setting the value to components from the FindObjectsOfType list's

Scene Management

-

How to reproduce it:
1. Open the attached project 'PrefabReset.zip'
2. Load the 'SampleScene' scene
3. Select the 'prefabObject' prefab in the Hierarchy window
4. In the Inspector window, find an 'Auto Set Script (Script)' component and right-click on the header
5. In the appeared Context menu, click on the 'SetValueAuto' item and notice that Value has changed to '5'
6. Select on 'prefabObject (1)' prefab in the Hierarchy window and notice that the 'Auto Set Script' component's Value is '5'
7. Enter the Play Mode
8. Observe the Text in the Game View

Expected result: All prefabs has an Auto Set Script component with Value set to '5'
Actual result: Only 'prefabObject' prefab has an Auto Set Script component with Value set to '5'

Reproducible with: 2018.4.32f1, 2019.4.21f1, 2020.2.7f1, 2021.1.0b10, 2021.2.0a7

Notes:
- Not reproducible with GameObjects
- Not reproducible with components (like BoxCollider, etc.)
- The overridden Value is set only to the prefab's instance in which the Context Menu > 'SetValueAuto' was clicked
- Select 'prefabObject (1)' prefab and in the Inspector view click on the Overrides drop-down. Notice that in the appeared window are no overrides

  1. Resolution Note:

    When setting properties directly in the Editor (without using SerializedProperty) extra care have to be taken for overrides on Prefab instances to be recorded. There are two options here:
    1) Ensure to call PrefabUtility.RecordPrefabInstancePropertyModifications(yourChangedObject) after changing properties.
    2) Or call EditorUtility.SetDirty(yourChangedObject). This will indirectly call RecordPrefabInstancePropertyModifications at the end of frame for all dirty objects.

    The reason the context clicked object has overrides recorded in the repro is that the context menu item when executed will mark the script component dirty (and therefore end of frame automatically have overrides calculated)

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.