Search Issue Tracker

Fixed in 5.3.5

Votes

9

Found in

5.3.0f4

Issue ID

754351

Regression

Yes

[Prefabs] OnWillSaveAssets doesn't work for Prefabs when applying any changes made to it

Assets Management

-

Steps to reproduce:

1. Open attached project
2. Open 'Test' scene
3. Drag 'TestPrefab' to the scene to create a game object
4. Add or remove any component from the game object
5. Click 'Apply' in the inspector to apply the changes to prefab

Expected behavior: OnWillSaveAssets gets called for the prefab object
Actual behavior: OnWillSaveAsset doesn't get called

NOTE: When you save the scene, with the changed prefab in it, in 5.2 versions OnWillSaveAssets gets called for all changed objects, including the TestPrefab. In 5.3 and 5.4 - it's only called for scene object.

Reproduced with: 5.3.0f4, 5.4.0b1
Partially reproduced with: 5.2.4f1

Comments (4)

  1. 4bd8ea6d03cc29358150761cb75c23f3?d=mm

    jp_topps

    Apr 19, 2016 20:24

    I'm seeing this, as well, still in v.5.3.4f1. As a note: IsOpenForEdit() gets called upon initially selecting the prefab in the project, and can automatically prevent it from being edited at that point, if you return false. OnWillSaveAssets() is triggering as @jorgenpt said, after hitting 'save project' when making changes this way.

    When using the approach of hitting 'apply' or dragging from the scene to update the prefab, i only see calls for the prefab.meta file (which gets it's creation date changed... which isn't really desirable either!)

    This is a problem for us because we are trying to create a simple lock/unlock flow for working with scenes and prefabs after the yaml-merge (unity merge) has proven to be unreliable for us.

  2. F0edb9ae1259743340c5f8a75e5097b2?d=mm

    jorgenpt

    Feb 23, 2016 17:23

    (The fact that OnWillSaveAssets is not called when you hit apply in 5.2, but just when you hit "save scene" or "save project", is fine. That's just how the serialization works in Unity.)

  3. F0edb9ae1259743340c5f8a75e5097b2?d=mm

    jorgenpt

    Feb 23, 2016 17:22

    After hitting this ourselves (and having our bug marked as a dupe of this), I'd like to point out that this is a) a regression, and b) still happening in 5.3.2p4.

    The issue is that previously when you hit "apply" on a prefab in the scene, then saved the scene / the project, it would call OnWillSaveAssets for the asset. As of 5.3, it no longer calls OnWillSaveAssets for the prefab.

    It *does* call OnWillSaveAssets if you edit the prefab while inspecting the prefab directly in the project view (and not the scene view.) It's both inconsistent and impractical.

  4. Bb821971e4273f3407ccb558ac30a354?d=mm

    RandomThought

    Jan 04, 2016 02:25

    Typically I find that OnWillSaveAssets isn't called until the scene is saved, at least not when applying prefabs. I figured this was deliberate.

    For example if I have a scene with lots of particle emitters in a prefab & this prefab is placed around a scene, I might try applying lots of different settings to the prefab and view the changes to the loaded scene. The apply updates the instances of the prefab in the scene immediately. After a while I may decide that none of the changes I have made improved anything and go.. oh well, I'll reload the scene and throw away my failed attempts. If the prefabs were saved when pressing apply then any changes I'd made to prefabs would have been saved immediately even though I hadn't chosen to save, I just wanted to update the instances in the scene to see if it worked. If it saved on pressing apply I'd have to rely on multiple undos to get back into my previous state and then apply a previous version. It seemed a little counter intuitive when first working with prefabs but on reflection it's hopefully the way they are intended to work. If it was saving immediately in 5.2 I'd consider that a bug.

    Ideally I'd like something like a 'Save' button on prefabs such that both 'Apply' and immediate save behaviors could be available. Either that or an attribute on a component class e.g. [SaveOnApply] etc.

    AFIK you can use an inspector GUI button to apply the change immediately using the AssetDatabase and PrefabUtility classes.

    Fingers crossed that this isn't actually a bug :op

All about bugs

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