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
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
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.
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.
– MorpheusHmm, if it worked in the previous version, then it looks like a bug. Has anyone reported it?
– EndogenI'll setup a project to reproduce this, then I'll submit.
– MorpheusNot a valid solution for us anyway because it happens on a "uLink Network View" component that is not editable by script.
– RecognizorOh, I don't have any experience with uLink...
– EndogenYou can change the floats in your script to the “correct” value, then select the prefab in ProjectView and chose revert to Prefab.
This does not solve the problem, which is that the changes made by editor scripts on prefabs are not saved.
– CovenantThats true, but a better workaround then running through 80 Scenes by hand, much faster and less prone.
– ReorganizeI’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.,
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
– ConvoyMaybe 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
I’ve found a solution to similar problem:
- Make some changes in the prefab instance using editor script.
- Unlink prefab instance: PrefabUtility.DisconnectPrefabInstance(yourInstance);
- 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.
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.
© 2022 - 2024 — McMap. All rights reserved.
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.
– MorpheusHappen to us too with "uLink Network View" component modified by the assignement wizard. It makes this version of Unity (3.5.0f5) totaly useless :(
– RecognizorAny update on this bug? Really annoying one, as it prevent us from upgrading to Unity 3.5!...
– Covenant