Obstacle spawning

Godot Version

4.3

Question

Hello everyone, I need help with my obstacle spawning. The code works, but my obstacles do not appear on the screen. I even used a print statement to debug, but they still won’t appear. In the Remote tab, the obstacles are visible but do not appear on the screen. My scene setup includes a CanvasLayer, a Parallax Background, a Static Ground, a Character2D, and a Camera2D. Any assistance would be appreciated!

func generateObstacles():
	# If the obstacles array/list is empty
	if obstacles.is_empty() or lastObs.position.x < score + randi_range(100, 500):
		# Pick any random obstacle and assign it to the obstacles type variable
		var obsType = obstaclesType[randi() % obstaclesType.size()]
		var obs
		obs = obsType.instantiate()
		
		var obsHeight = obs.get_node("Sprite2D").texture.get_height()
		var obsScale = obs.get_node("Sprite2D").scale
		
		var obs_x: int = screen_size.x + score + 100
		var obs_y : int = screen_size.y - ground_height - (obsHeight * obsScale.y / 2) + 150
		obs.position = Vector2i(obs_x, obs_y)
		lastObs = obs
		addObstacles(obs, obs_x, obs_y)

func addObstacles(obs, x, y):
	obs.position = Vector2i(x, y)
	add_child(obs)
	obstacles.append(obs)

If you look at the obstacle in the remote tab, is the position something that should be visible on the camera? Does it work if you set global_position instead?

By the way, it looks like you’re setting the obstacle’s position twice, which is redundant, but shouldn’t be the problem.

I’m having some trouble understanding your question. However, I can see the obstacles listed in the Remote tab. Could you please clarify your question?

If you click the obstacle in the remote tab, you can see its properties in the inspector, including its position. If you can’t see the obstacle in the game, it might be somewhere outside of the screen, and you can use the inspector to see, if that’s the case.

Thank you for the clarification, when I do that, it does appear to be on screen just that it does not show in the game itself.

I had an issue with my scene tree, but after I fixed it, everything started working.