Object invisible?

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

I tried to spawn objects using this method:
But the objects are invisible. When i let the objects print their position and check the remote scene tree they get spawned correctly but just aren’t visible. When I run the game with visible collision shapes the collision shapes of the objects do not show neither.

here is the script that spawns the objects:
extends Node2D

onready var plants = $Plants
onready var tileMap = $TileMap

export(PackedScene) var Plant

var rng = RandomNumberGenerator.new()

func _ready():

func _on_Plant_popped():

func plant():
	var plant = Plant.instance()
	plants.call_deferred("add_child", plant)
	var spawnpoints = tileMap.get_used_cells_by_id(1)
	plant.position = (tileMap.cell_size) * spawnpoints[rng.randi_range(0, spawnpoints.size()-1)]

and here is the object’s code:

extends Area2D

onready var animationPlayer = $AnimationPlayer
onready var popTimer = $PopTimer
onready var berryShape = $BerryShape

var FLOOR = Vector2(0, -1)

signal popped()

func _ready():
	connect("popped", get_node("/root/TestWorld"), "_on_Plant_popped")
	connect("popped", get_node("/root/TestWorld/GUI/HungryBar/MarginContainer/TextureProgress"), "_on_Plant_popped")

func _on_Plant_body_entered(body):
	if body.get_name() == "HummingBird":
		if body.state == body.ATTACK:
			berryShape.set_deferred("disabled", true)

func _on_PopTimer_timeout():
:bust_in_silhouette: Reply From: astrale-sharp


first thing, this code will run and instance forever right? this might eat up all your memory and cause the bug, just try the plant() in ready while you test to make sure this is not that
for instance since you defer, he might defer indefinitly the call cause he is busy doing the signals

what is your plants object? and why do you call_deffered: try calling directly add_child

in doubt try:
var Plant = load(“your/scene/path”) #maybe it’ll work

Yesssss that worked, the call deffered seemed to be the problem indeed, it was implemented like that because previously the platn was a kinematic body…


rubendw03 | 2020-04-13 20:08

oh , you’re so very welcome :wink:

astrale-sharp | 2020-04-21 06:36