2

I creating game about tank battle. I have already wrote script which be constructor for all tanks Node. Part of this script export tank's Texture and then make Node. this look like this:

export (Texture) var chassis_texture;

func _init():
    var chassis_collision = CollisionShape2D.new();
    var chassis_shape = RectangleShape2D.new();
    var chassis_sprite = Sprite.new();

    chassis_sprite.texture = chassis_texture;
    chassis_shape.extents = chassis_texture.get_size()
    chassis_collision.shape = chassis_shape;

    add_child(chassis_sprite);

So even if I specify the texture in the editor, chassis_texture equals Null How fix this? thanks in advance and sorry for my English.

BUTURUM
  • 21
  • 3

1 Answers1

2

Godot calls the method _init just before setting the exported variables. I went over the order in another answer, here. Because of that, when _init runs, your exported variable is still null. The simplest solution is to move your code to _ready.

Theraot
  • 31,890
  • 5
  • 57
  • 86