Prefab settings overwritten during runtime???

Hey guys

I hope this can be replicated somehow: I recently added a line that instantiates a prefab from the Resources folder, into which I had to move my prefab assets as well.
What happens is that when playing the game, the settings in my prefab (for example an int rotState) are changed PERMANENTLY. I have never seen this before and think under no circumstances should this happen. It’s always 0 in the prefab and becomes 3 when ending game mode.

Destroyer dstr = Instantiate(Resources.Load("Prefabs/Destroyers/myPrefab"), sometransform) as Destroyer; // happens here
GameObject dstrGO = (GameObject) Instantiate(Resources.Load("Prefabs/Destroyers/myPrefab"), sometransform); // and here

Now I moved them back to their original folder, and instead of using Resources.Load() I set a variable via Editor. Still: they get changed all the time. What the f*ck guys. This is in the truest sense game-breaking. I cannot continue working anymore because everytime my prefabs are changed. Maybe I should add that this concerns prefab variants. I reverted all my code but still… I rotate the clone and the prefab changes

Using 2019.4.18f1 LTS

Quick help much appreciated!

OK, although I thought this was impossible and should not happen, here is what I finally figured.

I have a button-class that does

player.selectedDestroyer = destroyerPrefab; // prefab set via Editor

This is a reference to the prefab obviously.
Now when the player rotates this variable via selectedDestroyer.rotate() it actually calls this method on the very prefab element.

Bug or feature … I’d say bug, because I would not expect to totally screw your prefabs from within the game ô.O

1 Like

nobody interested?
Unity team?

ô.O

Well, you’re modifying the prefab asset instead of the game instance, so that’s what you get. I don’t think there’s anything sleek and easy that Unity can do to prevent this mistake since they shouldn’t make it impossible to modify source assets because of editor code. I’d argue against investing in systems that somehow reset all prefabs after play mode since that just wouldn’t be feasible performance-wise. Also, again, there’s editor code that may be run intentionally, so Unity really doesn’t know if you want to modify your prefab or only an instance.