Another health issue

After we added the healthPoints = -1 my player suddenly showed 400% health from a clean start (i.e. no save file). I realized that I forgot to remove the SerializeField and an initial value of 200 was being set and overriding the -1. After removing the SerializeField nothing changed. I was still getting 400% health. After lots of digging I found that the original serialized value of 200 was still in the prefab’s yaml and after manually removing the entries (I had to do the Character and Enemy prefabs, too) my health was back to normal.

Just putting this here in case someone else has a similar issue

3 Likes

Yes, once a value is serialized, the system restores the value if it’s found within the Yaml
An alternate way of handling this is to replace the [SerializeField] tag and then go through the inspectors of the prefabs and reset them to their default values.

1 Like

Thanks @bixarrio :slight_smile: I understand the struggle, and appreciate sharing the discovery of bugs and their solutions.

Since it’s the same topic, I wanted to add that I came across a second scenario that causes the HUD to read an hp percentage above 100%. It’s a possible race condition in BaseStats if you cache the Experience component in Start(). I like caching, but was taught to use Start(), so it’s taking a while to break that habit. sheepish aura. GetLevel() can be called before Start() (was every time I tried it) so that the null check in GetLevel() (if (experience == null) { return currentLevel; } ) always returned the level I had serialized for my Player. This was solved by resetting my serialized level to 1, and then realizing it was a race condition and caching the component correctly in Awake(). :smiley:

1 Like

Privacy & Terms