Changes to prefab parameters not being saved
Asked Answered
S

6

0

In Unity 3.5.0b6 I have a script attached to a prefab with some Serialized floats.
When I change the floats in the unity editor, they update fine. But any changes I make are not saved to the .prefab file

Sinuosity answered 26/3 at 19:36 Comment(3)

This is annoying. It's happening to me too. I had a script that updated some prefab instances on specific scenes, now I need to go over 80+ scenes manually. It's taking forever. The changes done by script are never saved to the prefab instances, even after you save a scene, it reverts to the prefab default values.

Morpheus

Happen to us too with "uLink Network View" component modified by the assignement wizard. It makes this version of Unity (3.5.0f5) totaly useless :(

Recognizor

Any update on this bug? Really annoying one, as it prevent us from upgrading to Unity 3.5!...

Covenant
E
0

I’m not sure I completely understand your problem, but if it’s something like this:

You have a Player prefab with a PlayerStats.cs script attched to it
PlayerStats.cs has a maxHealth attribute which was originally 100, but now you edited it so that it’s 50
You expect the Player prefab to update maxHealth to 50, but it doesn’t :frowning:

Then try commenting out the attribute in the script, going back into the Unity editor (pulls in the script, removes the attribute from the prefab), then go back to the script and un-comment it, then go back into Unity and it should pull in the new script with the new value for the attribute.

Endogen answered 8/2, 2012 at 19:10 Comment(5)

That's not the case. Let me show what happens in Unity 3.5b: 1 - Have a prefab on a scene; 2 - Run a custom wizard script that alters some values on the instantiated prefab (not the prefab itself); 3 - Save the scene; 4 - Hit play. Now the prefab instance values were reverted to the prefab original values and the changes your wizard script made are lost forever :( SInce this newest Unity version, prefab instances are only saving values that you modify by hand. Wizard scripts became broken.

Morpheus

Hmm, if it worked in the previous version, then it looks like a bug. Has anyone reported it?

Endogen

I'll setup a project to reproduce this, then I'll submit.

Morpheus

Not a valid solution for us anyway because it happens on a "uLink Network View" component that is not editable by script.

Recognizor

Oh, I don't have any experience with uLink...

Endogen
R
0

You can change the floats in your script to the “correct” value, then select the prefab in ProjectView and chose revert to Prefab.

Reorganize answered 12/3, 2012 at 14:44 Comment(2)

This does not solve the problem, which is that the changes made by editor scripts on prefabs are not saved.

Covenant

Thats true, but a better workaround then running through 80 Scenes by hand, much faster and less prone.

Reorganize
A
0

I’m seeing something similar when I convert a project from 3.4.2… some of my prefabs are “going stock” and reverting to default settings across the board.,

Ankle answered 1/4, 2012 at 17:5 Comment(1)

If you still have a 3.4 copy of your project, here is a script that fixes this problem: http://forum.unity3d.com/threads/132489-Resetting-PrefabOverride-Flags-for-Instantiated-Prefabs-in-3.4.x?p=897802&viewfull=1#post897802

Convoy
C
0

Maybe this discussion is helping? They suggest calling EditorUtility.SetDirty(arg) when using Editor scripts to modify prefabs/prefab instances: http://unity3d.qatohost.com/questions/62455/how-do-i-make-fields-in-the-inspector-go-bold-when.html

Convoy answered 17/4, 2012 at 16:25 Comment(0)
J
0

I’ve found a solution to similar problem:

  1. Make some changes in the prefab instance using editor script.
  2. Unlink prefab instance: PrefabUtility.DisconnectPrefabInstance(yourInstance);
  3. Link it with its prefab again: PrefabUtility.ReconnectToLastPrefab(yourInstance);

After these manipulations it can be saved well and shows in bold in editor, and instances holds all their links.

Jeffersonjeffery answered 7/7, 2012 at 0:56 Comment(0)
P
0

If you are changing the serialized values by script…
Calling UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(YOUR_COMPONENT) on your instance’s component will solve this problem. Note that if you want the Editor to detect the scene change you also have to call UnityEditor.EditorUtility.SetDirty(YOUR_INSTANCE) as well.

Patronizing answered 26/3 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.