Disable CollisionShape2d and hide Sprite on KinematicBody2D instances

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

Tree:
This is my tree  of the node I want to instance

SCRIPT:
Here is my first statement:
Preload the node
Creation of the instances:
Instances
When the user makes a mistake, I match the error number:
In this routine I want to disable the CollisionShape2d and hide th Sprite
When the game stops:
Destroy all instances
When the user wants to replay the game:
re-creation of the instances

My problem is: I am not able to hide the Sprite and disable the CollisionShape2d
I tried set_defered, free, queue_free nothing works.
Can you help me please.
Michel

Can You share images in other way ? A lot of antivruses block these

Inces | 2021-11-17 13:54

I do not have a webSite. I use DropBox to send images.
Michel

mabelair88 | 2021-11-17 14:18

:bust_in_silhouette: Reply From: Merlin1846
$Sprite.visible = false
$Kinematicbody2d/CollisionShap2d.set_deferred("disabled",true)

That always works for me; also sorry if this doesn’t answer you’re question, the images won’t load.

:bust_in_silhouette: Reply From: mabelair88

Since the images are not shown here is my data.
Tree: cloture.tscn
cloture (Type: node2D)
|__ k1 (Type: KinematicBody2D)
****|__ brun (Type: CollisionShape2d)
********|___ b1 (Type: Sprite)

SCRIPT: in game.tscn
###Here is my first statement:
var barreau1 = preload(“res://scenes/cloture.tscn”)
var barreau2 = preload(“res://scenes/cloture.tscn”)
###Creation of the instances:
k1 = barreau1.instance()
brun1 = k1.get_node(“k1/brun”)
b1 = k1.get_node(“k1/brun/b1”)
k2 = barreau2.instance()
brun2 = k2.get_node(“k2/brun”)

###When the user makes a mistake, I match the error number:
match compteur:
1:
$explosion.start()
brun1.set_deferred(“disabled”,true)
b1.visible = false
brun2.set_deferred(“disabled”,true)
b2.visible = false
2:
$explosion.start()
bleu3.set_deferred(“disabled”,true)
b3.visible = false
bleu4.set_deferred(“disabled”,true)
b4.visible = false

###In this routine I want to disable the CollisionShape2d and hide th Sprite

I am not able to hide the Sprite and disable the CollisionShape2d
I tried set_defered, free, queue_free nothing works.
Michel

Please cancel this question. I did solve the problem. Instead of preloading the scene, I instance my scene in the tree of my game.
Thank you Merlin1846. Now it is working fine.
Michel

mabelair88 | 2021-11-22 05:25