- Home /
Unity automatically "applies prefab changes" to selected GameObject when going to Play mode
When going to Play mode in Editor, the Game Object selected in hierarchy applies its changes to its Prefab, like pressing the Prefab Apply button in inspector. This has caused a lot of mistakes in our project, if designers forget to select a non-prefab object before pressing play.
It started when we upgraded to Unity 2017.3.0f3 from 2017.1.1p2. It doesn't happen on new projects, but it occurs with every PC when editing this project.
Is it a Unity bug or some obscure setting we have accidentally turned on? Any ideas why this could be happening?
I think its a bug with your project because I'm using 2017.3 and it is not happening to me...
Answer by murgonen · Mar 08, 2018 at 01:48 AM
I finally solved the issue hooking a logging callback to PrefabUtility.prefabInstanceUpdated
, through which I was able to get the call stack of the prefab applying and found the culprit.
The problem in our case was a 3rd party plugin (Fabric) that caused this from a DLL. It has a malfunctioning setting for "Playmode Persistence" somebody had turned on.
Below is the code I used for finding the problem.
[InitializeOnLoad]
public class PrefabApplyDetector
{
static PrefabApplyDetector()
{
PrefabUtility.prefabInstanceUpdated = s => { Debug.LogError("Prefab is applied!", s); };
}
}
Your answer
Follow this Question
Related Questions
Cannot Set Sorting Layer Name in Nested Canvas Prefab 0 Answers
Particle System deselected automaticlly whenever i go into play mode 2 Answers
Problem with a prefab, need help 0 Answers
Lighting/Appearance changes between play mode and build 1 Answer
prefab instantiated by script containing ShadowCaster2D bugs out 0 Answers