How to add a scene in Area2D after tigger by _on_area_2d_area_entered

Godot Version



Hi, I’m super new to coding and need ur help badly :sob:

So basically I want a scene to appear in after it was triggered in Area2D by dragging stuff (scene) over it. Because I’m try to make a plant appears in a growing zone. I followed this tutorial , the code was around 19:00. But want to change the way plant is growth so I did separate scene from other tutorial for the plant. And Idk how to make it appears.

This is my code for ‘Growing zone’

extends StaticBody2D

var plant = Global.plant_selected
var plant_growing = false
var plant_growth = false
var seed_scene = preload(“res://scenes/coffee/coffee_seed.tscn”)

func _physics_process(delta):
if plant_growing == false:
plant = Global.plant_selected

func _on_area_2d_area_entered(area):
if not plant_growing:
if plant == 1:
plant_growing == true
var instance = seed_scene.instantiate()

  •   	add_child(instance)*
  •   	print("planted")*

the codes are what I trying to make scene appear

change the seed_scene variables preload path to where your scene is.

Does the line print("planted") get executed?

I would troubleshoot the code by using breakpoints.
Put a breakpoint onto print("planted") and trigger it.
Then head over to your Remote Tab and navigate to your Growing Zone object. Does the Coffee_seed scene exist as a child node?
If yes, what is its position? Is it there where you want to be?

Also, i am deeply worried about your func _on_area_2d_area_entered(area): because you don’t check if the area that triggered the function is valid. I hope you got that sorted out elsewhere (maybe by use of Collision Layer/Mask)

The instantiation looks correct and I am not sure if the problem is that

  • the seed_scene instance is not visible on area_entered / there is a “planted” print
  • there is a compile error
  • the function does not trigger at all / there is no “planted” print