Godot Version
4.3dev6
Question
I created a health component and that health component has an export var for a health bar scene that I created. I drag the progress bar into the export slot in the inspector. I set the progress bar max value in the _ready() function of the health component but when I run the game it says that I can’t set max value of Nil. Am I missing something that I need to do to make this work? I am not sure what else I need to do other than drag the node to the export slot.
In the image below the script is the one that is attached to the HealthComponent. You can see the export var for the progress bar and I dragged the node in the scene tree to the export row in the inspector. You can also see the max_health set in _ready(), that is where it’s failing
1 Like
Just a wild guess here, I think this has to do with the order Godot loads scenes in the scene tree from top to down. It might be that healthbar has not been loaded when the healthcomponent is looking for it.
Try adding healthbar as a child of healthcomponent.
1 Like
From the tree order it should work. What is the error?
Does your progressbar have a property max_value?
Yeah I thought that the order was good since the HealthBar is before the HealthComponent. The error I am getting is:
Invalid assignment of property or key ‘max_value’ with value of type ‘float’ on base object of type ‘Nil’.
When I look at the Stack Variables the health bar is
Unfortunately that didn’t work. I am still getting the same error as above
Hmm, I use this technique often.
I guess you should make sure that progressbar is actually assigned to the node instance in the scene with the inspector.
Edit: Which you do…
1 Like
I wonder if it’s a 4.3 bug.
1 Like
this is a pretty common error most anyone face, but no idea why it got an error of null but the node is there
basically you call something too quick on _ready from a node that the method of property of called node is not yet existed. hence why it’s null
at your func _ready(): first line add this:
await get_tree().physics_frame
1 Like
Yes, this is what I was thinking too. I was going to try and recreate it in 4.2 and see if I get this issue
try what i answered first, because it shouldnt be an engine bug, someone just got similar to this issue on other post.
I got a similar issue, somehow.

When my object is created with “instantiate child scene” in the editor, it works fine.
When I create the assembler object myself with .new()
I have this error.
EDIT: I fixed it by using preload()
and instantiate()
instead.
.new() creates a new object of the type of the script.
So you created a new HealthComponent without a definition for the health_bar variable export.
The PackedScene is the node complete with the attached script and defined health_bar export variable.
I also have a similar problem, I’m calling a method inside a node to set the values of the mana, health and exp bar of my character.
I’m sure that the method is receveing the values, but when I try to set the valuer to for example “health_bar.max_value” this error shows up:
Invalid assignment of property or key 'value' with value of type 'float' on a base object of type 'Nil'.
The funny thing is, when I drag and drop the Progress bar from the editor to the code, this error doesn’t show up.
Any suggestions?
I had the same problem. I was going to ask here, but then suddenly solved it.
My problem was that I had an @export array of cameras that I added in the inspector, that worked splendidly for days. Until suddenly without changing any related code, the exported array became to be always recognized as Nil and nothing worked to fix it.
What solved it for me is that I moved that @export array to just above _ready(). I have no idea why it solved it. Also I have no idea why it broke in the first place as I did no changes to the code.
So just sharing what (for whatever reason) fixed it for me.
(Moving it just above _ready() might not even be the fix by itself, maybe just moving around things somehow ‘unclogged’ something in the interiors of Godot.
I don’t know…)
UPDATE: So, after writing this comment, this started happening again for many other scenes as well… And what I noticed is that, sometimes changing the @exports in the scene file itself carries over to your already instanced scenes. And sometimes they don’t. So I managed to fix the problems by changing the instanced scenes’ exported vars to be the same as in the base scene. (The confusing part is that sometimes when you change things in the base scene, they do carry over to already instanced scenes, and sometimes not. So if this issue with @exports arises, I suppose it’s good to also check the instanced scenes vs. base scene and whether they differ. At least this was my experience.)
2 Likes
Thank you! Same problem, I had @export an array of meshes wich I wanted to change the material, and it didnt carry over to the instantiated scene, very weird!
I can try using call_deferred() on it.
1 Like