Script changes not applying to prefabs

I’m running into a weird issue, or maybe I’ve been oblivious this whole time. When editing the enemy health script, I decided to bump the maxHitPoints variable up to 7. However, that value doesn’t get updated. If I attach the script to the ram prefab again, it shows me two copies (one to be deleted after troubleshooting, of course). One shows the old value, one shows the new. I added some other fields within the script, they showed up on both copies. However, changing any variables within those scripts continues to do nothing to the prefab. So, my question is:

Is it normal behavior for variables changed within prefabs to ignore those updates, or have I messed something up somewhere?

NoChange
ScriptChange

Hi,

If put a prefab in the scene and edit values, those values will look different.
If you then change the prefab values, it will change everything,
apart from values you already changed in the scene.

I think thats what you meant anyways?

Good question, and thanks for the quick reply.

To clarify, I’m talking specifically about the main prefab within the assets folder. I haven’t attempted to test on anything added to the scene.

Hi,

Welcome to our community! :slight_smile:

What you discovered is the normal behaviour in Unity. When you assign a script to the Inspector (of a game object or a prefab), the Inspector takes the initial value from your code but then it controls the component object. This makes sense because if you have different enemies you might want to use different values for them. You assign individual values to their respective Enemy or EnemyHealth component in the Inspector. If you change something in your code, the Inspector is not supposed to override your individual values. Otherwise, you would have to reassign all values each time you change something in your script.

Did this clear it up for you?


See also:

Interesting, I’m shocked I never noticed that before. That makes perfect sense, thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms