• 2D
  • Child doesn't initialize from script

I have been making my first game in Godot. It is going to a strategy game, but as of now I have met a problem which I cannot overcome on my own.

Basically, I have a superclass called Unit and a class named MotorizedInfrantry which extends the Unit class. The MotorizedInfantry class is a Node2D with a Sprite2D child(named Image).

Here is the script for Unit

And here is the script for MotorizedInfantry

All I want to do is to load a texture for my sprite by doing this: $Image.texture = load(image_path)

When trying to access my Image node from my MotorizedInfantry script I get an error explaining to me that the Image node was not found. I tried to access my node with a new Image script. This time there was no error, but the the texture did not load.

When trying to print get_parent().image_path the editor prints nothing. It's just as if there is no Sprite node at all. How can I solve this issue? Also, I am using Linux, in case that has anything to do with the solution.

I am instantiating my MotorizedInfantry in my Main scene's _ready function.

4 days later

Hi the easy way to solve your issue

1 - remove script from Sprite Image

2 - add this line to your Main Script Scene $MotorizedInfantry/image.texture = load(inf1.image_path)