Strange error that isn't affecting noticeable gameplay.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spafnar

I recently wrote a code that would allow a fireball to shoot out from the bottom of the playerview, and then would be affected by gravity and fly back downwards. The purpose of the code had to do with flipping v, and ultimately the code had to check for the global position instead of the velocity. This is the code:

var direction = “up”
var last_pos = global_position.y

func _process(_delta):
if last_pos < global_position.y:
	last_pos = global_position.y
	direction = "down"
elif last_pos > global_position.y:
	last_pos = global_position.y
	direction = "up"
match direction:
	"up":
		$Sprite.flip_v = false
	"down":
		$Sprite.flip_v = true

I was happy to see it finally flipping like I wanted to, but after closing the debuger I noticed there was a large amount of errors in my debug menu. It was as follows:

“get_global_transform: Condition “!is_inside_tree()” is true. Returned: get_transform()”

There was 26 of them and I’m guessing that number comes from how many fireballs I allowed to spawn. Does anyone know what this error does or is, and if it affects anything.

:bust_in_silhouette: Reply From: automatrio

It seems like you forgot to call add_child() after you instanced the fireball. Does it have a parent?

The script for instancing the fireball in the main scene is as follows:

	var ball_spawn_location = $ChomperPath/ChomperSpawnLocation
ball_spawn_location.offset = randi()

var ball = Fireball.instance()
self.add_child(ball)

var direction = $ChomperPath/ChomperSpawnLocation.rotation + PI/2
ball.position = ball_spawn_location.position

var velocity = Vector2(rand_range(ball.min_speed, ball.max_speed), 0)
ball.linear_velocity = velocity.rotated(direction)

Spafnar | 2021-02-06 19:46