Godot Engine

Godot Engine

なかの31 Jul 11, 2023 @ 8:46pm
Godot ignoring @export variable values on inspector.
I just noticed this odd issue with godot when trying to add a rat monster on my project.

So, I'll use one of the variables to describe the problem:
I assigned on the "CharacterScript" the "@export var InitialHealth = 50", notice that the default value is 50.

The player and the rat monster, both inherit from CharacterScript, but each have different script files.
In the Rat case, the value of InitialHealth is set to 20 in the inspector.

The problem is, when the game tries to do the calculation to check how much status the character will have, on the rat, instead of taking from InitialHealth the value 20, which was set directly on the monster, it takes 50, which is the default value from InitialHealth.

The oddest thing about this, is that when I check the Remote part when debugging my project, and check the Rat monster status, I see that InitialHealth value is as I set, 20, but still, the MaxHealth after the calculation was set to 50.

This is confusing, it seems like there's 2 versions of InitialHealth, the one from the Rat monster script, and the one from CharacterScript.

Anyone else noticed this?
< >
Showing 1-1 of 1 comments
なかの31 Jul 11, 2023 @ 9:07pm 
Nevermind, I found out why:
Better not to use certain scripts, like those messing with such variables on scripts called by "_init()".
Instead, call them on "_ready()" script.
< >
Showing 1-1 of 1 comments
Per page: 1530 50

Date Posted: Jul 11, 2023 @ 8:46pm
Posts: 1